Jump to content

how to run shell script with browser action as trigger


Recommended Posts

I have a complicated situation

I want to execute a php script that runs in the background while a browser script is used as trigger.


I use wamp CLI to execute a php script like this:


php test.php



I want to execute this script in the browser with this script


$outp = shell_exec("php test.php");

echo '<br>';
echo $outp;
echo '<br>';


It doesnt work. The page in the browser is giving no output

I can do shell_exec("whoami"), or shell_exec('dir'); So this works, but executing a script not.


What causes this error?




Link to comment
Share on other sites

Do I have to set a path or so for the Command Line Interface , PHP_CLI ?

If so, how should this be done?



as there are many OS and approaches of PHP I have some additional info about my set up.

I use WAMP 3.1.9 with windows 10. PHP version 7.3.5

Edited by BrainPill
Link to comment
Share on other sites

On 1/21/2020 at 12:39 PM, niche said:

what happens when you add a path? 

I tried that. Are there specific rules I should follow? 

What actually happens when you call a php shell_exec command? Where will the command look to start something? 


Edit: I tried the following


$var = php_sapi_name();

the output is: apache2handler

In the manual of php is a number of outputs mentioned 


aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, cli-server, continuity, embed, fpm-fcgi, isapi, litespeed, milter, nsapi, phpdbg, phttpd, pi3web, roxen, thttpd, tux, and webjames.



I dont know if this is the solution but it coudl be so does anyone know if the sapi can be set to cli or cli-server maybe?


Link to comment
Share on other sites

I think the issue is hello_world.php in not a command.

This works fine:

shell_exec("mkdir data5");

This might help - 


Edited by niche
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...