I have a (possibly dumb) question.
I have a script made in php, constructed for cli usage. Works fine when I run it from the command line, no problem there. The problem is that the site I'm working on has ssh restrictions on the hosting server and I cannot ssh there to run it. Hence my question: how can I run the script from another php that is web-accessible? Already tried with exec(), system(), etc.
The main problem is that I need he $_SERVER['SHELL'] variable set, and when the call is comming from a web browser of course php doesn't set it.
Any ideeas will be greatly apreciated, thanx.
There are many possibilities why exec() and related function calls are not working for you.
- Your webhost does not have PHP-CLI installed. Just a webserver module
- You need to use the full path to the php binary for lack of a decent shell environment. E.g.
/usr/bin/php <script>
instead of php <script>
.
- Your webhost has installed PHP-CLI on a non-standard path (e.g.
/usr/local/bin/php
, or /opt/php5/php
)
- The webserver user does not have rights to access the php binary
- Et cetera..
maybe update the php script to be both an include and a cli script.
use
__FILE__
to check if it's a file, then read the params. otherwise do nothing.
and as an include just call the function you want directly.