|
How to Run any PHP Script as a Windows Service with AlwaysUp |
Start your PHP script in the background when your PC boots. Keep it running 24/7 or schedule it to restart several times a day
PHP is a popular programming language. It is often integrated with web servers but works just as well when creating standalone applications.
To set up a PHP script to run as a background windows service with AlwaysUp:
-
Download and install AlwaysUp, if necessary.
-
Download and
manually install
the PHP package, if necessary.
We have installed PHP in C:\PHP and we'll reference that location throughout this tutorial.
-
Next, let's ensure that your PHP script can run normally from the command line.
-
Start a command prompt (Start button > Run > cmd.exe)
-
In the window that appears, type the full path to the PHP executable (php.exe) followed by the full path to the script you wish to run as a windows service. Be sure to quote each component containing at least one space!
Since we have placed PHP in C:\PHP, and our script is C:\PHP\sample-php-script.php, our command line is:
C:\PHP\php.exe C:\PHP\sample-php-script.php
-
Hit the Enter key to execute the command line. If your script doesn't work as expected please resolve the issues now.
For example, if you get the
MSVCR110.dll is missing error,
please install the
Visual C++ Redistributable package for Visual Studio 2012.
Note that if your script doesn't work here then it won't work with AlwaysUp!
Here is the code of our simple script:
And here is the result from running it on the command line:
Everything looks good!
-
Next, start AlwaysUp.
-
Select Application > Add to open the Add Application window:
-
On the General tab:
-
In the Application field, enter the full path to the PHP executable (php.exe). Again, this is C:\PHP\php.exe for our installation.
-
In the Arguments field, enter the full path to your PHP script.
We want to run our sample script, C:\PHP\sample-php-script.php.
-
In the Name field, enter the name that you will call this application in AlwaysUp.
We have used My PHP Script but you can specify virtually anything you like.
-
If you only want your script to run periodically (that is, not 24x7), click over to the Restart tab and choose when to run.
For example, if you wish to kick off the script at 6 AM every day, check the Not immediately and At boxes and
enter that time in the corresponding field.
However we'll stick with the default of restarting immediately to keep our script running continuously.
-
Click the Save button. In a couple of seconds, an application called My PHP Script will show up in the AlwaysUp window.
It is not yet running though.
-
To start the service, which will kick off the PHP script, choose Application > Start "My PHP Script".
In a few seconds, the state should transition to Running:
On Windows 8/7/Vista and Server 2012/2008, your PHP script will be running in the background on the
isolated Session 0.
Select Tools > Switch to Session 0 to move to Session 0 where you should see a CMD window hosting your script:
-
That's it! Next time your computer boots, your PHP service be launched immediately, before anyone logs on.
We encourage you to explore the many other AlwaysUp settings that may be appropriate for your environment.
PHP script not working properly as a Windows Service?
-
From AlwaysUp, select Application > Report Activity > Today... to bring up a HTML report detailing the interaction between AlwaysUp and your application.
The AlwaysUp Event Log Messages page explains the more obscure messages.
-
Some PHP scripts need to be run in a user account to have access to their settings and resources.
In that situation, edit your application in AlwaysUp, switch to the Logon tab and enter the user name and password
of the account where you can run your PHP script normally (the one you were logged in to for step 3).
- Consult the AlwaysUp FAQ for answers to commonly asked questions and troubleshooting tips.
- Contact us and we will be happy to help!
|
Over 84,000 installations, and counting!
|
 |
|
Rock-solid for the past 15+ years!
|
Fully Compatible with 140+ Applications...
|