Monday, October 25, 2021

[SOLVED] How can I run a php script on a remote server?

Issue

I have a remote Apache/2.2.16 (Debian) Server where I want to do intervalled jobs like every 2 hours do this, at 12.00 do this. So, I wrote a php file which can do this but I have to start it via the browser and have to keep the browser window open to keep the script running. I heard I could execute a php script via console, but I don't have access to it.

How can I run the script without access to the console and without having my browser opened?


Solution

Set up a cron job for this task. You can set this up on the server or on any other computer that runs at the given time.

On a Linux or Mac OS machine, open a terminal and type crontab -e.

Add something like this to the end of the file:

0 12 * * * wget http://url.com/your/script.php -O /dev/null

This will call the script every day at 12:00. Make sure wget is installed.



Answered By - Phil