How do I run a PHP script without actually opening it?

Chinmay S July 5, 2014
Pinterest Stumbleupon Whatsapp

How to run a PHP script without actually opening it?

I want the PHP script to run at regular intervals (2 months).

For example: Let’s say I run some kind of business where I receive a specific amount of money every 2 months. If I get the payment in the time frame then it’s fine but, if I didn’t receive payment, then the script should send me an email.

I don’t want to open the webpage and allow the script to check and notify me, that’s time consuming. A real world example is IFTTT.

  1. Bruce E
    July 7, 2014 at 4:40 am

    What OS is this web server running on (Windows/Linux/Mac) and what server is it (Apache/IIS)? Why did you choose to do this with PHP instead of one of the many other scripting languages available on the platform which are likely to be better choices (PowerShell, any *nix shell, etc)?

    As far as scheduling, you can use the Windows Scheduler or cron to initiate the process and just make sure you properly terminate the script when the process is done so you are releasing allocated resources.

  2. Oron J
    July 5, 2014 at 9:14 pm

    Well, PHP is a web server technology, so the web page *has* to be served in some way, which implies reading it in a browser. I suppose you could write something that would simulate a web browser but without displaying anything, but it would be as simple to set up a scheduled task in Windows (or crontab on Linux or Mac OS) to open that URL in a web page. All you'd need to do is close it once it opened, and if even that is too much effort, you could probably automate the closing of the page (details would depend on your OS & web browser and your choice of automation software).

    With PHP, I think it would be impractical to trigger the script from the cloud, since it only runs when an actual web page is being served. Of course, if you have control of the server with the page, you could probably run the scheduled task right there...