Return to Snippet

Revision: 13568
at April 28, 2009 08:40 by g0mer


Initial Code
function backgroundPost($url,$params) {
	
	$post_string = ''; // fallback
	
	if(!empty($params)) {
        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($parts['host'], 
	isset($parts['port'])?$parts['port']:80, 
	$errno, $errstr, 30);
		 
	if(!$fp) {
		return false;
	} else {
		$out = "POST ".$parts['path']." HTTP/1.1rn";
		$out.= "Host: ".$parts['host']."rn";
		$out.= "Content-Type: application/x-www-form-urlencodedrn";
		$out.= "Content-Length: ".strlen($post_string)."rn";
		$out.= "Connection: Closernrn";
		if (isset($post_string)) $out.= $post_string;
		 
		fwrite($fp, $out);
		fclose($fp);
		return true;
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Asyncron HTTP request

Initial Tags
php, textmate

Initial Language
PHP