如何在PHP中同步执行Shell命令 [英] How to execute shell commands synchronously in PHP

查看:404
本文介绍了如何在PHP中同步执行Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过cmd运行多个脚本(5个脚本),我想确保除非并且直到第一个脚本完成,否则第二个脚本不应启动.因此,在第一个脚本完成后,只有第二个脚本应该是第三个脚本,依此类推. 目前,我正在使用以下代码执行此操作

I need to run multiple scripts(5 scripts) via cmd, I want to make sure unless and until the first script finishes the second should not initiate. Thus after first script completes then only second should being then third one and so on.. Currently I am using the following code to do this

exec ("php phpscript1.php ");
exec ("php phpscript2.php ");
exec ("php phpscript3.php ");
exec ("php phpscript4.php ");
exec ("php phpscript5.php ");

我认为这些脚本是异步运行的,任何建议人员都可以使这些脚本同步运行.

I think these scripts run asynchronously, any suggestion guys so that these scripts can be run synchronously.

推荐答案

PHP exec 除非您使用& ;,否则将等到被调用程序的执行完成,然后再处理下一行.在字符串的末尾以在后台运行程序.

PHP exec will wait until the execution of the called program is finished, before processing the next line, unless you use & at the end of the string to run the program in background.

这篇关于如何在PHP中同步执行Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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