note 97493 deleted from function.curl-setopt by crell

From: Date: Thu, 31 Mar 2022 20:55:50 +0000
Subject: note 97493 deleted from function.curl-setopt by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217983@lists.php.net to get a copy of this message
Note Submitter: sjungwirth at google mail dot com ---- I couldn't find a way to force a curl request to go to a particular IP address, but you can do it with fsockopen: <?php $ip = '123.45.67.89'; $fp = fsockopen($ip, 80, $errno, $errstr, 5); $result = ''; if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /path/to/the/file.ext HTTP/1.1\r\n"; $out .= "Host: www.exampl.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); } ?> I needed it to test the response from a set of servers behind a load balancer.

« previous php.notes (#217983) next »