以后台方式运行php脚本,如何使用php exec(),运行另一个脚本并在后台运行,而不是等待脚本完成...

在花时间充分了解我自己的问题以及可以回答的方式之后,我已经准备好了我的解决方案。

感谢大家提出的建议,以及在提出问题时我的随意和毫无准备。

上述问题的答案取决于许多因素,例如您所指的操作系统,您正在运行的php模块,甚至是您正在运行的Web服务器。所以如果我不得不再次提出这个问题,我要做的第一件事就是陈述我的设置。

我想在两种环境中实现这一点:

1.)运行Zend服务器社区版的Windows 7。

2.)Linux(我的操作系统是Linux odysseus 2.6.32-5-xen-amd64#1 SMP Fri Sep 9 22:23:19 UTC 2011 x86_64)

为了做到这一点,我希望它在部署到Windows或Linux时以任何方式工作,所以我使用php来确定操作系统是什么。

public function createInstanceAction()

{

//determines what operating system is Being used

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')

{

//This is a windows server

//call a seperate php process to run independently from the broswer action

pclose(popen("start php /path/to/script/script.php","r"));

}

else

{

//assuming its linux, but in fact it simply means its not windows

// to check for linux specifically use (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN')

exec('php -f /path/to/file/script.php >/dev/null 2>&1 &');

}

//the browser will not hang around for this process to complete, and you can contimue with whatever actions you want.

//myscript log any out put so i can capture info as it runs

}简而言之,一旦你理解了问题就提出问题。有很多方法可以实现上述目标,这只是一个适用于我的开发和生产环境的解决方案。

谢谢大家的帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值