Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Does an asynchronous POST request. (Cannot access output)
- *
- * @static
- * @throws Exception
- * @param string $url
- * @param array $params
- * @return void
- */
- public static function curl_post_async($url, $params)
- {
- $post_params = array();
- foreach($params as $key => &$val) {
- if(is_array($val)) $val = implode(',', $val);
- $post_params[] = $key . '=' . urlencode($val);
- }
- $post_string = implode('&', $post_params);
- $parts = parse_url($url);
- $fp = fsockopen('127.0.0.1',
- isset($parts['port']) ? $parts['port'] : 80,
- $errno, $errstr, 30);
- if($fp == 0) throw new Exception("Couldn't open a socket to " . $url . " (" . $errstr . ")");
- $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($post_string) . "\r\n";
- $out .= "Connection: Close\r\n\r\n";
- if(isset($post_string)) $out .= $post_string;
- fwrite($fp, $out);
- fclose($fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement