PHP Four common asynchronous processing solutions 1, using the front-end AJAX processing
$.ajax ("do.php", {name: ' ityangs ', Job: ' PHP Programmer '});
2. Use the Popen function to execute local files
Pclose (Popen (' php/var/www/do.php & ', ' R '));
3. Use Curl
Set Curl Timeout Curlopt_timeout 1 (minimum 1), so the client waits 1 seconds and the Curl request address must be an absolute path
$param = Array (
' name ' => ' ityangs ', '
job ' => ' PHP Programmer '
);
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://www.example.com/do.php");
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, Http_build_query ($param)); Converts an array to a URL request string
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, curlopt_timeout, 1);
Curl_exec ($ch);
Curl_close ($ch);
4, using the Fsockopen function, you need to splice header part
function DoRequest ($url, $param =array (), $timeout =10) {
$urlParmas = Parse_url ($url);
$host = $urlParmas [' host '];
$path = $urlParmas [' path '];
$port = Isset ($urlParmas [' Port '])? $urlParmas [' Port ']:
$errno = 0;
$errstr = ';
$fp = Fsockopen ($host, $port, $errno, $errstr, $timeout);
$query = Isset ($param)? Http_build_query ($param): ';
$out = "POST". $path. " Http/1.1\r\n ";
$out. = "Host:". $host. " \ r \ n ";
$out. = "Content-length:". strlen ($query). \ r \ n ";
$out. = "content-type:application/x-www-form-urlencoded\r\n";
$out. = "connection:close\r\n\r\n";
$out. = $query;
Fputs ($fp, $out);
Fclose ($FP);
$url = ' http://www.example.com/do.php ';
$param = Array (
' name ' => ' ityangs ', '
job ' => ' PHP Programmer '
);
DoRequest ($url, $param);
Attention:
1, if the use of Apache as a Web server, so that PHP support asynchronous first must be in the Apache configuration file httpd.conf configuration Enablesendfile
On
2, in the asynchronous execution of the PHP file recommended add a few two configurations:
ignore_user_abort (TRUE);//Ignore Client disconnect set_time_limit (0);//Set execution does not timeout