简体   繁体   English

PHP exec()函数加速

[英]PHP exec() function speedup

I am using the exec() function in PHP to run a command via command prompt. 我在PHP中使用exec()函数通过命令提示符运行命令。 However the time which is needed to process this command using PHP is much longer compared to when I actually run the command on the CLI . 但是,与我在CLI上实际运行该命令相比,使用PHP处理该命令所需的时间要长得多。

Any idea how I can improve its performance or make more efficient calls? 知道如何改善其性能或进行更有效的通话吗? I am trying to run powershell scripts. 我正在尝试运行Powershell脚本。

The exec() function needs to create another process, a virtual shell, run the command, wait for the reply, and then return with the results, if any. exec()函数需要创建另一个进程,虚拟外壳程序,运行命令,等待答复,然后返回结果(如果有)。

That's the sort of thing you can expect whenever you want PHP, or some other platform, to communicate outside of itself. 每当您希望PHP或其他平台在自身外部进行通信时,您都可以期望得到这种东西。

There are the following alternatives: 有以下几种选择:

  • Simple shell commands have corresponding PHP functions. 简单的shell命令具有相应的PHP函数。 This includes basic file manipulation. 这包括基本的文件操作。
  • If you're using exec to call another program, such as ImageMagick, there may be an interface available to PHP directly. 如果您正在使用exec调用另一个程序,例如ImageMagick,则可能有直接可用于PHP的接口。
  • There may be alternative PHP scripts available to do the same job as a command line process. 可能还有其他PHP脚本可用于完成与命令行过程相同的工作。

Other than that, maybe not. 除此之外,也许不是。

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

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