简体   繁体   English

PHP使过程保持活动状态

[英]PHP keeping process alive

I am struggling to find a solution to a problem where a user visits to page1.php and this page include another page2.php which takes lot of time (~5 minute) to complete all the computation but the results of the computation doesn't need to be displayed to user. 我正在努力找到用户访问page1.php的问题,并且此页面包含另一个page2.php的问题的解决方案,该过程花费大量时间(〜5分钟)来完成所有计算,但是计算结果却没有需要显示给用户。 So, its not worth to make the user to wait for its completion. 因此,让用户等待其完成并不值得。

I am looking for a solution where user should visit page1.php and after some necessary check listing it should display message to the user that his request processing has started. 我正在寻找一种解决方案,其中用户应访问page1.php,并在进行一些必要的检查后将其显示给用户有关其请求处理已开始的消息。 And on the back end page2.php should complete all of its working even if user should have closed window. 在后端,即使用户应该关闭窗口,page2.php也应该完成所有工作。

check out this link How do I make an asynchronous GET request in PHP? 查看此链接如何在PHP中发出异步GET请求? if you would like to get the result displayed on the request page, use file_get_contents 如果要在请求页面上显示结果,请使用file_get_contents

Offload the actual computation to a standalone process (a cron job, or a custom daemon) and implement some sort of job queue (eg, using a database). 将实际的计算卸载到一个独立的进程(一个cron作业或一个自定义守护程序)并实现某种作业队列(例如,使用数据库)。 So your front-end (the PHP website) would add the data to a database table, and then periodically check back on it (eg by reading a 'progress' column or something); 因此,您的前端(PHP网站)会将数据添加到数据库表中,然后定期对其进行检查(例如,通过读取“ progress”列或其他内容); the processing daemon would look in the table to see if there are any new jobs, and if so, start processing them, updating the table as needed. 处理守护程序将在表中查找是否有任何新作业,如果有,则开始处理它们,并根据需要更新表。

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

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