Heim > php教程 > php手册 > 解析PHP实现多进程并行执行脚本

解析PHP实现多进程并行执行脚本

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 20:30:37
Original
1391 Leute haben es durchsucht

本篇文章是对PHP实现多进程并行执行脚本进行了详细的分析介绍,需要的朋友参考下

由于php的进程是不支持多线程的,服务器空间,美国空间,香港服务器,有些场景为了方便以及提高性能,可以用php实现多进程以弥补这个不足:

复制代码 代码如下:


#!/usr/bin/env php
$cmds=array(
array('/apps/bin/launcher.php','charge/promotion_props_stat.php','mobile',1),
array('/apps/bin/launcher.php','charge/promotion_props_stat.php','mobile',2),
array('/apps/bin/launcher.php','charge/promotion_props_stat.php','click',1),
array('/apps/bin/launcher.php','charge/promotion_props_stat.php','click',2),
array('/apps/bin/launcher.php','charge/promotion_props_stat.php',1),
array('/apps/bin/launcher.php','charge/promotion_props_stat.php',2)
);

foreach($cmds as $cmd){
$pid=pcntl_fork();
if($pid==-1){ //进程创建失败
die('fork child process failure!');
}
else if($pid){ //父进程处理逻辑
pcntl_wait($status,WNOHANG);
}
else{ //子进程处理逻辑
pcntl_exec('/usr/local/bin/php',$cmd);
}
}


Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage