Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP exec to run a file

Tags:

php

exec

I am trying for last 3 hours to tell PHP to run a simple file. I am using wamp server for windows in local host (Windows 8)

I've tried with exec() working with:

 echo exec('whoami');

I got response nt authority.

Also tested with:

if(function_exists('exec')) {
echo "exec is enabled";
}

So it probably works?

I am trying to run a file called tester.php

When I include it, its working, when I require it its working. I need to execute it in background. When I refresh file, code is working without any error, it writes to the database normally.

When i try to exec it its not working.

I tried :

       exec("php http://localhost/diplomski/program/defender/tester.php");
       exec("php-cli http://localhost/diplomski/program/defender/tester.php");
       exec("http://localhost/diplomski/program/defender/tester.php");

Not working, also tried:

        exec("php http://127.0.0.1/diplomski/program/defender/tester.php");
        exec("php-cli http://127.0.0.1/diplomski/program/defender/tester.php");
        exec("php-cli d:\wamp\www\diplomski\program\defender/tester.php")

Not working also tried:

        exec("php tester.php");
        exec("php-cli tester.php");
        exec("tester.php");

Also tried:

         $WshShell = new COM("WScript.Shell");
         $oExec = $WshShell->Run("D:\wamp\bin\php\php5.3.13\php-win.exe -f d:\wamp \www\diplomski\program\defender/tester.php", 0, false);

Tried this, its refreshing infinitely and not working:

        exec("php d:\wamp\www\diplomski\program\defender/tester.php");
        exec("php-cli d:\wamp\www\diplomski\program\defender/tester.php");
        exec("d:\wamp\www\diplomski\program\defender/tester.php");

I'm starting to pull my hair out here. First time I'm trying to use exec() and I'm not very good with it or with the commands.

like image 310
Avi Avatar asked Nov 13 '13 18:11

Avi


1 Answers

Give the full path to the PHP executable and the full path to the PHP script. You can save the output in $output to see what the script produced:

exec("d:/path/to/php.exe d:/wamp/www/diplomski/program/defender/tester.php", $output);
print_r($output);
like image 120
AbraCadaver Avatar answered Sep 17 '22 18:09

AbraCadaver