Created
November 9, 2010 09:04
-
-
Save bastianallgeier/668881 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
* | |
* Copyright by Pete Warden: http://petewarden.typepad.com/searchbrowser/2008/06/how-to-post-an.html | |
* Adapted by Bastian Allgeier: http://bastian-allgeier.de | |
* | |
*/ | |
function async($url, $params) { | |
// parse the url to get out the different parts we need | |
$parts = @parse_url($url); | |
if(!$parts) return false; | |
// determine the right port | |
$port = (isset($parts['port'])) ? $parts['port'] : 80; | |
// build a connection to the socket | |
$socket = @fsockopen($parts['host'], $port, $errno, $errstr, 30); | |
// connection failed | |
if(!$socket) return false; | |
// build the post request we'd like to send | |
$out = "POST " . $parts['path'] . " HTTP/1.1\r\n"; | |
$out .= "Host: " . $parts['host'] . "\r\n"; | |
$out .= "Content-Type: application/x-www-form-urlencoded\r\n"; | |
$out .= "Content-Length: " . strlen($data) . "\r\n"; | |
$out .= "Connection: Close\r\n\r\n"; | |
// add our query parameters | |
if(!empty($params)) $out .= http_build_query($params); | |
// writing all that to the socket | |
$write = @fwrite($socket, $out); | |
// writing failed | |
if(!$write) return false; | |
// finally close the socket | |
@fclose($socket); | |
// everything went fine | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment