'execute php file with php.exe

I want to execute a php file using php.exe installed with Xampp.

Xampp install dir is C:\xampp\ So the path of php.exe is C:\xampp\php\php.exe

I changed the DOCUMENT_ROOT in apache config file, so, my root is the drive O:\

The php file that I want to execute simply make another file in the same folder. Just to see if the execution work.

[make.php] Path => O:/make.php

<?php
    $f=fopen(date("d_m_Y_H_i_s").".txt","a");
    fclose($f);
?>

When I open my browser and start http://localhost/make.php the txt file is generated correctly.

So all works! Now I want to do the same thing not using the browser but php.exe

Right click on php.exe, run as administrator, ( UAC disabled and no account password ) type "O:\make.php" press enter but nothing happens...

Tried also with "O:/make.php", "make.php", "php make.php", "php O:/make.php", "php O:\make.php".

Someone have any ideas?



Solution 1:[1]

From Windows You must use the Task Scheduler (from the Control Panel)

Create a new task which will launch the PHP binary, with the cron.php script path as an argument every 5 minutes

Examples :

"c:/pathtophp.exe c:/web_folder/glpi/front/cron.php " With Wampp

c:/wampphpphp.exe c:/wamp/www/glpi/front/cron.php With Xampp

Run : C:/(…)xampp/php/php.exe -f cron.php

Start in : C:/(…)xampp/htdocs/glpi/front

Isaac Aguilar

Solution 2:[2]

On powershell or commad prompt php -r "echo PHP_VERSION;" gives the version

or exe any other php command

Solution 3:[3]

Because you use XAMPP you need to specify the path like so :

C:\xampp\php\php.exe O:/make.php

edit: You can also add a variable enter image description here Windows 10 and Windows 8

In Search, search for and then select: System (Control Panel)

Click the Advanced system settings link.

Click Environment Variables.

In the section System Variables find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Now in any BATCH file (.bat) just use %PHP%. enter image description here

So if you change your mind and use another package or use directly PHP, you will just need to change the Path of the variable. ?

Solution 4:[4]

You can write a batch-file with following content and put it in the same directory as your make.php file.

php make.php

With that batch you can execute your php-file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivan Aguilar
Solution 2 VPDD
Solution 3
Solution 4 Mr. K. O. Rolling