BrainPill Posted January 20, 2020 Share Posted January 20, 2020 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 More sharing options...
niche Posted January 20, 2020 Share Posted January 20, 2020 space in the filename. Link to comment Share on other sites More sharing options...
BrainPill Posted January 21, 2020 Author Share Posted January 21, 2020 14 hours ago, niche said: space in the filename. I tested : shell_exec("phptest.php"); to get rid of the space. Not sure if it is possible if there can be a space in the filename while saved? never heared about that Link to comment Share on other sites More sharing options...
BrainPill Posted January 21, 2020 Author Share Posted January 21, 2020 (edited) Do I have to set a path or so for the Command Line Interface , PHP_CLI ? If so, how should this be done? EDIT: 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 January 21, 2020 by BrainPill Link to comment Share on other sites More sharing options...
niche Posted January 21, 2020 Share Posted January 21, 2020 what happens when you add a path? Link to comment Share on other sites More sharing options...
BrainPill Posted January 26, 2020 Author Share Posted January 26, 2020 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? Link to comment Share on other sites More sharing options...
BrainPill Posted January 26, 2020 Author Share Posted January 26, 2020 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(); var_dump($var); the output is: apache2handler In the manual of php is a number of outputs mentioned Quote 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. https://www.php.net/manual/en/function.php-sapi-name.php 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 More sharing options...
BrainPill Posted January 26, 2020 Author Share Posted January 26, 2020 (edited) Or should I change the php.ini settings? I figured out I have (at least) 2 different php.ini files. One in the apache dir and 1 in the php dir Edited January 26, 2020 by BrainPill Link to comment Share on other sites More sharing options...
dsonesuk Posted January 26, 2020 Share Posted January 26, 2020 (edited) If you access the php localhost FROM taskbar (wamp->php->localhost (I think)) page and look for php.ini, it will identify the used file location. You can also add phpinfo() to a php page. Edited January 26, 2020 by dsonesuk Link to comment Share on other sites More sharing options...
niche Posted January 26, 2020 Share Posted January 26, 2020 The path for my WAMP is $file = "drive:/wamp64/tmp/filename_with_extention"; Link to comment Share on other sites More sharing options...
BrainPill Posted January 31, 2020 Author Share Posted January 31, 2020 It still does not work for me. What I tried is this: $output = shell_exec("A:/wamp64/test/batchscripts/hello_world.php"); echo '<br>'; echo $output; echo '<br>'; Link to comment Share on other sites More sharing options...
niche Posted January 31, 2020 Share Posted January 31, 2020 (edited) I think the issue is hello_world.php in not a command. This works fine: shell_exec("mkdir data5"); EDIT: This might help - https://hotexamples.com/examples/-/-/shell_exec/php-shell_exec-function-examples.html Edited January 31, 2020 by niche Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now