可以在后台运行PHP函数吗? [英] Possible to run a PHP function in background?

查看:116
本文介绍了可以在后台运行PHP函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用PHP 5.我有一个功能需要一段时间才能运行,

而且我没有''我希望用户必须等待它。是否有在后台运行此功能的方式?


感谢您的帮助, - Dave

Hi,

I''m using PHP 5. I have a function that takes a little while to run,
and I don''t want the user to have to wait while it does. Is there a
way to run this function in the background?

Thanks for your help, - Dave

推荐答案

la *********** @ zipmail。 com 写道:




我正在使用PHP 5.我有一个功能需要一段时间才能运行,

我不希望用户必须等待它。是否有一种

方式在后台运行此功能?


感谢您的帮助, - Dave
Hi,

I''m using PHP 5. I have a function that takes a little while to run,
and I don''t want the user to have to wait while it does. Is there a
way to run this function in the background?

Thanks for your help, - Dave



在Web服务器环境中,并非真的。但是如果您的托管公司允许,您可以启动CLI

工作来完成工作。或者你可以

排队请求(即在数据库中)并定期运行一个cron作业

来处理队列。


-

==================

删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================

Within the web server environment, not really. But you can start a CLI
job to do the work if your hosting company allows them. Or you can
queue up the request (i.e. in a database) and have a cron job run
regularly to handle the queue.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


7月28日晚上10:56,laredotorn ... @ zipmail.com

< laredotorn ... @ zipmail。 comwrote:
On Jul 28, 10:56 pm, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.comwrote:




我正在使用PHP 5.我有一个功能,需要一点时间运行,

我不希望用户必须等待它。是否有一种

方式在后台运行此功能?


感谢您的帮助, - Dave
Hi,

I''m using PHP 5. I have a function that takes a little while to run,
and I don''t want the user to have to wait while it does. Is there a
way to run this function in the background?

Thanks for your help, - Dave



嗯,有许多方法可以异步运行一个函数(即

不等到它返回)。一种方法是分叉过程。另一个

的方法是调用PHP扩展公开的一些异步函数,

然后你将如何得到它的结果?您可能需要从另一个脚本再次调用

函数来收集返回值。

第二次,它应该在一个信号量上阻塞,或者更好,在一个

消息队列中。看看那些。

Well, there are many ways you can run a function asynchronously (i.e.
not wait until it returns). One way is to fork the process. Another
way is to call some asynchronous function exposed by a PHP extension,
but then how will you get its result? You might have to call the
function again from another script, to collect the return value. The
second time around, it should BLOCK on a semaphore or better yet, on a
message queue. Look those up.


On 2008-07-28 19:56:49 -0700," la *********** @ zipmail。 com"

< la *********** @ zipmail.comsaid:
On 2008-07-28 19:56:49 -0700, "la***********@zipmail.com"
<la***********@zipmail.comsaid:




我正在使用PHP 5.我有一个功能需要一段时间才能运行,

而且我不希望用户必须等待虽然它确实如此。是否有一种

方式在后台运行此功能?


感谢您的帮助, - Dave
Hi,

I''m using PHP 5. I have a function that takes a little while to run,
and I don''t want the user to have to wait while it does. Is there a
way to run this function in the background?

Thanks for your help, - Dave



我们遇到了类似的问题,而且我们的大工作耗费了大量时间,我们将它分成了10个后台进程,这些进程过滤了大量的网址

数据库 - 10个进程中的每个进程都在主表中

记录的十分之一上运行。所以这就是我们所做的。


注意发送输出到''/ dev / null''压低了

进程的任何输出; PHP脚本的结果被写入另一个数据库

表。


最后的&符号&意味着在后台运行该过程

(优先级低于前台进程。)


当然这是一种方法,如果你可以使用正在使用

托管或专用服务器;如果您使用共享主机,您的ISP

可能会限制使用PHP exec()命令:

We had a similar problem, and our large job took so much time, we split
it up into 10 background processes which filtered URLs in a large
database -- each of the 10 processes were operating on 1/10th of the
records in the main table. So this is what we did.

Note sending output to ''/dev/null'' surpressed any output from the
process; results from the PHP script were written to another database
table.

The ampersand at the end & meant to run the process in the background
(as a lower priority than foreground processes.)

Of course this is an approach that can be used if you are using
colocation or a dedicated server; if you use shared hosting, your ISP
may limit the use of the PHP exec () command:


这篇关于可以在后台运行PHP函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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