简体   繁体   English

PHP长期任务

[英]PHP Long-term Task

Well, I want to be able to have PHP threads running in the background which are writing their result to a SQL database, which I use to display the information to end-user. 好吧,我希望能够在后台运行PHP线程,并将其结果写入SQL数据库,该数据库用于向最终用户显示信息。

My question is: How do I start aa new thread which can take some hours to finish from a PHP script? 我的问题是:如何从PHP脚本启动一个可能需要几个小时才能完成的新线程? I'm not quite sure about using cron jobs, because (as far as I know) I can only execute those based on the time and not based on when a new thread is required. 我不太确定要使用cron作业,因为(据我所知)我只能根据时间而不是根据何时需要新线程来执行那些作业。

There is a extension called pthreads that supports creating multiple threads. 有一个名为pthreads的扩展,支持创建多个线程。 See: 看到:

http://www.php.net/manual/en/book.pthreads.php http://www.php.net/manual/zh/book.pthreads.php

Although you should remember that depending on how you're running PHP you may find that spawning threads is not the most reliable way of completing a background task. 尽管您应该记住,根据您运行PHP的方式,您可能会发现生成线程并不是完成后台任务的最可靠方法。

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

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