Created
March 15, 2011 15:47
-
-
Save flesch/870910 to your computer and use it in GitHub Desktop.
Non-blocking background HTTP request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function async_request($url) { | |
$request = parse_url($url); | |
if (!isset($request['port'])) { | |
$request['port'] = 80; | |
} | |
$fp = @fsockopen($request['host'], $request['port'], $errno, $errstr, 30); | |
if ($fp) { | |
fwrite($fp, implode("\r\n", array( | |
sprintf('GET %s HTTP/1.1', $request['path']), | |
sprintf('Host: %s', $request['host']), | |
'Connection: Close' | |
)) . "\r\n\r\n"); | |
fclose($fp); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment