在Win上的PHP中派生/线程的最佳方法是什么? [英] What's the best way to fork/thread in PHP on Win?

查看:70
本文介绍了在Win上的PHP中派生/线程的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,用于检查许多(数千个)网站上的更新. 偶尔(随着站点数量的增加,频率会越来越高),我在更新其中一个站点时遇到了执行超时,整个脚本无济于事.

I have a php script that checks for updates on many (thousands) of sites. On occasion (more frequently as the number of sites increases), I get an execution timeout on the update of one of these sites, and the whole script goes down the drain.

我能想到的最好的主意是派生每个更新,因此,如果更新消失,整个更新将继续进行. 从我收集到的信息来看,似乎不需要依赖PHP线程,尤其是在Windows平台上(不幸的是,我必须在Windows平台上工作).

The best idea I could come up with is to fork each update, so if it dies, the overall update just continues. From what I gathered, it seems PHP threading isn't something to rely on, especially on a windows platform (which I unfortunately have to work on).

我考虑过使用curl作为分叉机制,但是在服务器上(在时间和处理能力上)会不会更昂贵?

I thought about using curl as a forking mechanism, but won't it be much more costly for the server (in time and processing power)?

我很高兴听到有关PHP分叉/线程化的一些想法和经验...

I'd be happy to hear some ideas and experience about PHP forking/threading...

谢谢, 厄默尔.

推荐答案

好吧,最后我进行了卷曲操作,效果很好.

Well, at the end I went for curl, and it works just fine.

我需要跨平台的解决方案,因为我是在Mac上开发的,而在这种情况下,生产服务器是Windows.这意味着pcntl不可能.

I needed a cross-platform solution, as I develop on a Mac while in this case the production serer is Windows. That meant pcntl was out of the question.

我担心将数千个curl请求发送到我自己的服务器可能会占用它,并在当时困扰网站上的用户,但是我弄错了.

I was worried that sending thousands of curl requests to my own server might hog it and bother users on the site at the time, but I was mistaken.

但是,我确实必须在启动所有curl调用的脚本中添加set_time_limit(0),否则它将超时.

I did, however, have to add a set_time_limit(0) to the script that initiates all the curl calls, otherwise it just times out.

这篇关于在Win上的PHP中派生/线程的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆