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, Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812684 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 Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812688 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? Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812697 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); } ?> Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812698 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? Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812707 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 the else is being executed? Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812709 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 Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812711 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! Link to comment https://forums.phpfreaks.com/topic/154551-solved-fsockopen-problem/#findComment-812714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.