PHP并发通过Cron [英] PHP Concurrency via Cron

查看:123
本文介绍了PHP并发通过Cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个脚本需要作为单独的进程并发运行。我的计划是有一个cron作业,以固定的间隔执行这些脚本的多个实例。这是个好主意吗?这种方法的优点/缺点是什么?有没有其他的选择,我需要考虑?

I have a few scripts that need to run concurrently as separate processes. My plan is to have a cron job that executes multiple instances of these scripts at a set interval. Is this a good idea? What are the pros/cons to this approach? Are there any other options I need to consider?

底线:我试图模仿多线程。任何竞争条件将通过代码处理(例如在DB中的设置状态等)。

Bottomline: I'm trying to mimic multithreading. Any race conditions will be handled via code (e.g. setting statuses in DB, etc.). The scripts are supposed to do processing intensive tasks (e.g. creating thumbnails, etc.).

推荐答案

您可以使用分叉。启动脚本将加载所有默认配置和初始化,然后fork子进程来进行处理。然后它可以监视进程,以查看它们是否仍在运行。
http://php.net/manual/en/function。 pcntl-fork.php

You can use forking. The startup script would load all the default configurations and initializations, then fork child processes to do the processing. It could then monitor the processes to see if they are still running. http://php.net/manual/en/function.pcntl-fork.php

这篇关于PHP并发通过Cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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