Skip to content

Instantly share code, notes, and snippets.

@leepowers
Created July 30, 2015 22:26
Show Gist options
  • Save leepowers/8af4e30bff53c4fad615 to your computer and use it in GitHub Desktop.
Save leepowers/8af4e30bff53c4fad615 to your computer and use it in GitHub Desktop.
PHP Spawn HTTP Request Fork HTTP Request
/**
* Launch a new PHP process at the given URL
* @param string $url
*/
public function spawn_request($url) {
$url_a = parse_url($url);
$port = isset($url_a["port"]) ? $url_a["port"] : 80;
$fp = fsockopen($url_a["host"], $port, $errno, $errstr, 30);
$output = "GET " . $url_a["path"] . "?" . $url_a["query"] . " HTTP/1.0\r\n";
$output .= "Host: " . $url_a["host"] . "\r\n";
$output .= "\r\n";
fwrite($fp, $output);
sleep(3); // Give the server and network a few seconds to start the request before closing the socket
fclose($fp);
if ($errno) {
$error_message = "Error in spawn_request fsockopen. Error number '$errno'. Error message '$errstr'";
error_log($error_message);
}
die;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment