vincenzo Posted July 17, 2009 Share Posted July 17, 2009 Hi, Given the file ClientHttpRequest.php (code given below), and given that it will be accessed as such from a web browser from multiple clients: http://<host name>/ClientHttpRequest.php?url=<some url>&port=443&arg1=somearg&arg2=somearg&arg3=somearg&path=/test.php&svr=<my server> Is the following ClientHttpRequest code thread safe? (Please note the last line of the code which is instantiating the class and calling the public method in the same line.) Thanks. ------------------------ <?php class ClientHttpRequest { public function __construct() { } public function post() { $host = $_GET['url']; $port = $_GET['port']; $req = "arg1=" . $_GET['arg1'] . "&arg2=" . $_GET['arg2'] . "&arg3=" . $_GET['arg3']; $http = "POST " . $_GET['path'] . " HTTP/1.1\r\n"; $http .= "Host: " . $_GET['svr'] . "\r\n"; $http .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"; $http .= "Content-Type: application/x-www-form-urlencoded\r\n"; $http .= "Content-Length: " . strlen($req) . "\r\n"; $http .= "Connection: close\r\n\r\n"; $http .= $req . "\r\n\r\n"; $fp = fsockopen ($host, $port, $errno, $errstr, 30); if (!$fp) { echo "Could not open a socket to host"; } else { // NO HTTP ERROR fputs($fp, $http); // Get final acknowledgement while (!feof($fp)) { $res .= fgets ($fp, 1024); } fclose ($fp); print $res; } } } (new ClientHttpRequest())->post(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/166377-noob-question/ 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.