views:

55

answers:

2

[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_getaddresses: 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

A: 

You forgot the $ symbol before thefile pointer variable

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

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?

wimvds
I don't understand what you're talking about. Take a look at this: http://php.net/manual/en/function.fsockopen.php. Regarding what I'm trying to achieve - I would have thought the question makes it quite clear. I need to open a socket so I can send some data to a remote server.
morpheous
Ok, then why don't you use tried and tested components (Zend Framework or PEAR) or PHP's [curl functions](http://php.net/manual/en/book.curl.php) to do this? And what you're doing wrong is that you're trying to open a socket to a URL, that just doesn't make any sense, you have to open a socket to an IP or a FQDN (fully qualified domain name).
wimvds
I am working on legacy code that uses the fsockopen() function call. It turns out you may be right after all regarding my use of url. I wrote a quick script to test opening a socket to www.google.com and that worked. Apologies for biting off your head earlier. I'll see if I can fix this
morpheous
BTW Here's a question that could help you see what you have to do if you want to stick to using sockets (and also how that mess can be converted to cleaner code using curl :p) : http://stackoverflow.com/questions/2957068/php-fsockopen-to-curl-conversion.
wimvds
@wimvds: +1 for all your help thus far. I have edited my question in the light of your feedback. Please see my edited question
morpheous