Run PHP CLI script from web page

I have a (possibly dumb) question. I have a script made in php built to use cli. Works well when I run it from the command line, no problem. The problem is that on the site I work on, there are restrictions on ssh on the hosting server, and I can not start it. Hence my question: how can I run a script from another php available on the Internet? Already tried with exec (), system (), etc. The main problem is that I need its variable $ _SERVER ['SHELL'], and when the call is sent from a web browser, of course php does not set it.

Any ideas would be much appreciated than x.

+4
source share
2 answers

There are many ways that exec () functions and related function calls do not work for you.

  • Your web host has PHP-CLI installed. Just a web server
  • You need to use the full path to the php binary due to the lack of a decent shell environment. For instance. /usr/bin/php <script> instead of php <script> .
  • Your web host has installed PHP-CLI on a non-standard path (e.g. /usr/local/bin/php or /opt/php5/php )
  • The web server user does not have permission to access the php binary
  • Et cetera ..
+1
source

maybe update php script to be both include and cli script.

use

 __FILE__ 

to check if this is a file, then read the options. otherwise do nothing.

and as include just call the function you want directly.

0
source

Source: https://habr.com/ru/post/1339359/


All Articles