PHP exec()函数加速

I am using the exec() function in PHP to run a command via command prompt. 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.

Any idea how I can improve its performance or make more efficient calls? I am trying to run powershell scripts.

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.

That’s the sort of thing you can expect whenever you want PHP, or some other platform, to communicate outside of itself.

There are the following alternatives:

  • Simple shell commands have corresponding PHP functions. 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.
  • There may be alternative PHP scripts available to do the same job as a command line process.

Other than that, maybe not.