InMotion Hosting Support Center

exec a php script

Category: How To

2013-03-23 4:29 pm EST

Hits: 1,366

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...


You must login before you can ask a follow up question.

You must login before you can submit an answer.

I can also add a cron job and run the script using that, but I just can't run it from a php web script!! why!??!?! :(
23 Points
2013-03-23 07:03 pm EST



5,889 Points
2013-03-25 11:53 am EST
Thank you for your question hiya83!

Scripts ran through a <a href="">cron job</a> 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 with the same code in your and it worked. We noticed when your script ran in your file, the following errors occurred.
<br /><p style="margin-left:20px;">[Sun Mar 24 03:34:25 2013] [error] [client] sh: /home/******5/public_html/ /bin/bash^M: bad interpreter: No such file or directory, referer: https://www.************.com/uploadalbum<br />
[Sun Mar 24 03:34:42 2013] [error] [client] /home/******5/public_html/ line 2: \r: command not found, referer: https://www.************.com/uploadalbum</p>
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 <a href="">code editor</a>. 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

You must login before you can post a comment about this answer.

Like this Question?

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

Social Login Joomla

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!