一个使用php做多进程的例子

yorgo yorgo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
PHP is not multithreaded. The "Ticks" feature is a way to get some of the benefits of multithreading.

<?
function foo($str) {
static $i = 0;

print "$str: $i<br>\n";
$i++;
}

register_tick_function("foo", "count");

declare (ticks = 6) {

for($i=0; $i<20; $i++) {
echo "$i<br>\n";
}

}
?>


Output:
0
1
2
count: 0
3
4
5
count: 1
6
7
8
count: 2
9
10
11
count: 3
12
13
14
count: 4
15
16
17
count: 5
18
19
count: 6

欢迎大家激烈讨论
...全文
评论 12
收藏 已收藏
分享
返回顶部
yorgo
基础编程 21,889 成员 140,329 内容