简体   繁体   English

如何在后台启动多个PHP脚本?

[英]How to fire off multiple PHP scripts in the background?

this side of PHP is rather new to me. PHP的这一方面对我来说还很新。

I am interested in firing off a large number (25-50) separate processes from a parent script. 我有兴趣从父脚本中解散大量(25-50)单独的进程。 I would like for the parent script to not wait for these other scripts to complete AND I would like for these other scripts to run in parallel. 我希望父脚本不要等待其他脚本完成,而我希望这些其他脚本并行运行。

Each script would run for a specified amount of time calling a webservice. 每个脚本将在指定的时间内运行,以调用Web服务。

Can anyone give me some direction with this? 有人可以给我一些指导吗? I'm not asking for a coded answer specifically, but I just need some guidance. 我并不需要特定的编码答案,但我只需要一些指导。

Much thanks. 非常感谢。

It really depends on what you want to achieve. 这实际上取决于您要实现的目标。 @Julien's forking method could work, but this is not preferable if your web service calls are data intensive. @Julien的派生方法可以工作,但是如果您的Web服务调用是数据密集型的,则这不是可取的。 I am not saying that forking is bad on the contrary it works, but with the ammount of different wev services you want to call you should have a way manage things better. 我并不是说相反,分叉是不好的,但是它起作用了,但是要调用大量的wev服务,应该有一种更好地管理事情的方法。

Another thing that you can do is base this on cronjobs. 您可以做的另一件事是基于cronjobs。 For example if you're calling these webservices for some users in your app create a queue - a DB table that you add records that need to be processed. 例如,如果您正在为应用程序中的某些用户调用这些Web服务,则会创建一个队列-一个DB表,您可以在其中添加需要处理的记录。 If you are using Cake use the Cake Shells . 如果您使用的是Cake,请使用Cake Shells Then set up cronjobs that call a the shells that processes these records every now and then. 然后设置cronjobs,调用cronjobs时不时地处理这些记录的shell。 Divide all services is separate queues - at least for those that are very different in logic. 将所有服务划分为单独的队列-至少针对逻辑上非常不同的队列。 This way you will also divide your risk because if there is a failure in one of the web service calls you would not jeopardise all in some way. 这样,您还可以分担风险,因为如果其中一个Web服务调用失败,您就不会以某种方式危及一切。 Have separate logging abilities for each queue which will enable you to quickly track down problems. 每个队列都有单独的日志记录功能,这使您可以快速查找问题。 With consuming web services very often problems are external to your application. 使用Web服务时,问题通常是应用程序的外部问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM