Mr.n Posted April 17, 2009 Share Posted April 17, 2009 Dear all, I have 2 webservers running apache+php... i developped a script from the server side to accept requests coming from the other server. when i try this script through the web browser it's working but when i try to invoke this script through php code nothing happen !! here is the code: $connection = fsockopen($host,80,&$error_number,&$error_desc,30); if($connection) { fputs($connection, "GET $URL HTTP/1.1\r\n\r\n"); $ok = true; } Thank you, Quote Link to comment Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 PHP user probably doesn't have permission to open sockets on your system. Quote Link to comment Share on other sites More sharing options...
Mr.n Posted April 17, 2009 Author Share Posted April 17, 2009 you mean the apache user? anyway how can grant the appropriate permission? it's the first time i use this function. Thanks Quote Link to comment Share on other sites More sharing options...
Mr.n Posted April 17, 2009 Author Share Posted April 17, 2009 it's seems that the socket is sucessfully created because the condition if($connection) evaluate to true. so any idea ? what might me the problem? Quote Link to comment Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 From the manual: <?php $fp = fsockopen($host, 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> Quote Link to comment Share on other sites More sharing options...
Mr.n Posted April 17, 2009 Author Share Posted April 17, 2009 i tried this as it appears in the manual but still now success. do you think changing the port number to > 1024 will fix this? Quote Link to comment Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 the else is being executed? Quote Link to comment Share on other sites More sharing options...
Mr.n Posted April 17, 2009 Author Share Posted April 17, 2009 no the else isn't executed. but it worked nows it's seems a / was added by mistake Thanks anyway. the manual example solves the problem Quote Link to comment Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 Yeah I bet there was just a problem using fputs. This is the area where PHP really gets messy. Glad it's working now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.