exec a php script

Category: How To

hiya83
Asked:
2013-03-23 4:29 pm EST

Hits: 724
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!

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!??!?! :(
hiya83
23 Points
2013-03-23 07:03 pm EST

OTHER ANSWERS

0

jamesr
Staff
5,889 Points
2013-03-25 11:53 am EST
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

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

Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

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: support@InMotionHosting.com
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!