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 $isedate > /t24alv2/iseoutput/$ticker-$isedate-$thistime.log &");
Now, I previously had the command running from a CGI script ("bash -x...") and it was much faster (instantaneous). Now it takes a painfully slow time for the script to run (> 10sec) and for the resulting page to render.
Any ideas why this is so slow? I'd still like to run the bash script from PHP and not CGI, since my entire site is being converted to PHP. Perhaps another function is more suitable? Any ideas would be appreciated.
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.
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.