RE: [PHP] Socket Question

From: Date: Wed, 16 Apr 2003 19:05:52 +0000
Subject: RE: [PHP] Socket Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144178@lists.php.net to get a copy of this message
If you are using the socket_ functions, I can't be of much help, I don't use them because the documentation says they are experimental. If you are using the more generic fsockopen stuff, this might be of assistance... You can have the remote script just echo, then the script that is opening the socket and doing the fputs gets the results via fgets. $fp = fsockopen($domain,80, $errno, $errstr, 30); fputs ($fp, "POST /testing/page2.php?$request HTTP/1.0\r\nHost: $domain\r\n\r\n"); while (!feof($fp)) { $return .= fgets ($fp,1280); } fclose ($fp); In this example, my remote file just returns a URL encoded query string either starting with "error=" in the event of an error, or "st=" if it worked and has data to pass back. The bad part is the headers are also part of the return, but you can parse the return pretty easily if you know what to expect from yout script. $lines = split ("\n",$return); foreach ($lines as $line){ if (substr($line,0,3) == 'st='){ //this is the line with the vars $temp = explode('&',$line); foreach ($temp as $passed){ $keyval = explode('=',$passed); ${$keyval[0]} = $keyval[1]; } } elseif (substr($line,0,6) == 'error='){ $temp = explode('=',$line); $errorno = $temp[1]; //we will need to take some kind of action header ("location: $errorpage?error=$errorno"); exit; } } > -----Original Message----- > From: Paul [mailto:pauljw338_c@speakeasy.net] > Sent: Wednesday, April 16, 2003 11:03 AM > To: php-general@lists.php.net > Subject: [PHP] Socket Question > > > I have a script opening a socket to another server where a php script > (running on Apache) does some work, then returns. I just allow the > receiving script to end at present. I would like to write to that socket > from the receiving script and I think socket_send or write would do the > trick, but I can't seem to find an example or the right syntax. Can > anyone help? > > TIA, > Paul > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#144178) next »