开发者

fsockopen() returns null pointer, and $errstr is empty (no error message)

开发者 https://www.devze.com 2023-01-09 23:46 出处:网络
[Edit] I have reedited the previous question - since I had misunderstood what was causing the problem - and therefore the ample snippet I had before was a red herring. Thanks to wimdvx, I have a clea

[Edit]

I have reedited the previous question - since I had misunderstood what was causing the problem - and therefore the ample snippet I had before was a red herring. Thanks to wimdvx, I have a clearer idea as to what is going on.

First of all, I am using code that is base on this one, to handle IPN notifications from Paypal.

I was unable to connect using fsockopen, so I wrote a small snippet (shown below), to try to connect to Paypal.

<?php
    $fp = fsockopen("www.sandbox.paypal.com/cgi-bin/webscr", 80, $errno, $errstr,30);
   if(!$fp) {
        echo "$errstr ($errno)<br />\n";
   }
   else{
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: www.sandbox.paypal.com/cgi-bin/webscr\r\n";
   $out .= "Connection: Close\r\n\n\n";
   fwrite($fp, $out);
   }    

?>

When I run this little script, I get the following error on my server:

PHP Warning: fsockopen(): php_network_getaddr开发者_运维百科esses: getaddrinfo failed: Name or service not known in /home/minime/test-socket.php on line 2 PHP Warning: fsockopen(): unable to connect to www.sandbox.paypal.com/cgi-bin/webscr:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/minime/test-socket.php on line 2 php_network_getaddresses: getaddrinfo failed: Name or service not

known (0)

Can anyone shed some light on how to fix this?

I am running Ubuntu 10.0.4 LTS on the server


You don't open a socket to a URL, you have to open it to an IP or a FQDN.

Using

$socket_ur = 'www.mywebsite.com';

could help.

But what are you trying to achieve exactly?


You forgot the $ symbol before thefile pointer variable

if(!$fp) { print "Bah, hambug!. Connect to $socket_url failed. Error: $errstr"; } ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消