exec a php script

Avatar
  • Answered
Hi,

So I am trying to exec a php standalone script from a php web script and am running into issues. The goal is to fire and forget the standalone script., which will be doing some lengthy work based on input from the web script (for testing purposes now, it's just write a string to a file somewhere). However, I can't seem to get it to run from the web script. I've tried shell_exec, exec, passthru, system and none of them works. I am using shared inmotion hosting for now (will move to VPS soon), but is there anything within the shared hosting that is preventing me from achieving this??

Note: I am able to run the standalone script directly by going to it from a browser URL and it seems to execute fine using that way...

Thanks!
Avatar
jamesr
Thank you for your question hiya83! Scripts ran through a cron job do not go through Apache like the Scripts on the servers for the web do. Apache may see a bad character in the script failing it when its ran. We were able to create a test.sh with the same code in your blah.sh and it worked. We noticed when your script ran in your blah.sh file, the following errors occurred.

[Sun Mar 24 03:34:25 2013] [error] [client 98.207.4.218] sh: /home/******5/public_html/blah.sh: /bin/bash^M: bad interpreter: No such file or directory, referer: https://www.************.com/uploadalbum
[Sun Mar 24 03:34:42 2013] [error] [client 98.207.4.218] /home/******5/public_html/blah.sh: line 2: \r: command not found, referer: https://www.************.com/uploadalbum

For some reason, when your file is ran, the interpreter is finding a "/r" before your script and failing to run the command. If you haven't already, try creating the script through the file manager and type the code through the code editor. If you are uploading the script through FTP, the file may be retaining characters in the file that causes the error. You should be able to run that bash command with no problem on shared. Best Regards, James R