Calling bash with PHP's shell_exec — slow

后端 未结 2 1208
难免孤独
难免孤独 2021-01-16 01:40

I\'m using PHP\'s shell_exec function to call a bash script on my server.

shell_exec(\"bash -x /tesladata/isetools/0-extractbytickerforweb.bash $ticker $ised         


        
相关标签:
2条回答
  • 2021-01-16 01:59

    For Windows users running Apache as an NT Service: It seems that you can greatly improve the shell_exec() or exec() performance by configuring the Apache service to run with a user account and not the default system account.

    For example, I found that running Apache as a standard NT Service resulted in shell_exec() commands taking 15-17 seconds (specifically, running svn commands). Changing the Apache service to run with a user account caused the time to drop to to 4-5 seconds--a huge difference.

    To do this, open the service control panel, right-click on the Apache service, and select Properties. Click on the Log On tab and change the "Local system account" radio button to "This account". Then specify which user account you want the service to use.

    Note that I'm not a Windows admin guru; running a service with a user account may have important implications that I'm not aware of.

    0 讨论(0)
  • 2021-01-16 02:00

    You can take a look at PHP's exec and system functions, however I don't really see a reason why they would speed up the execution of the script, worth a try though. I'm pretty sure it is an issue with apache (assuming you're using apache), not PHP the source of this conclusion being this bug thread.

    Also you really should be extremely careful of using these commands on a public website. Make use of escapeshellarg and escapeshellcmd.

    0 讨论(0)
提交回复
热议问题