Title: Run any PHP Script as a Window Services with alwaysup.
1Run any PHP script as a Windows service with
AlwaysUp
2Start 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.
3To set a PHP script to run as a background
Windows service with AlwaysUp
- Download and install AlwaysUp, if necessary.
- if necessary Download and manually install the
PHP package, - We have installed PHP in C \ PHP and we will
refer to that location throughout this tutorial.
4Next, let's ensure that your PHP script can run
normally from the command line.
-
Start the
command prompt (Start buttongt Rungt cmd.exe) - In the window that appears, type the full path
for the PHP executable (php.exe) and then you
want to run it as a Windows service with a full
path to the script. Be sure to quote each
component containing at least one space! - Since we put 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
5Hit 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
6And here is the result from running it on the
command line
7PHP related Information
- Tips to Brush up Your PHP Programming Skills
phpMyAdmin Definition
8Next, start AlwaysUp.
Select Application gt Add to open the Add
Application window
9On the General tab
- Enter the full path to the PHP executable
(php.exe), In the Application field. 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 you would call
this application in AlwaysUp. We have used My PHP
Script but you can specify virtually anything you
like.
10If 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
in the corresponding field. However we'll stick
with the default of restarting immediately to
keep our script running continuously.
11Click the Save button. In a few seconds, an
application called My PHP Script will appear in
the Alwaysup window. However it is not running
right now.
12To start the service, which will close the PHP
script, choose Applicationsgt Start "My PHP
Script" In a few seconds, the state should
transit in running
13On Windows 8/7 / Vista and Server 2012/2008, PHP
scripts are executed in the background of an
isolated session 0. Select Tools gt Switch to
Session 0 to move to Session 0 where you should
see a CMD window hosting your script
14That's it! Next time your computer boots, your
PHP service be launched immediately, before
anyone logs on. We recommend that you check many
other AlwaysUp settings that are appropriate for
your environment.
15PHP script not working properly as a Windows
Service?
- From AlwaysUp, select Applicationsgt Report
Activitygt Today ... to display an HTML report
that shows the details of the interaction between
AlwaysUp and the application. The AlwaysUp event
log message page explains 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
username and password of the account where you
can run your PHP script normally (the one you
were logged in to for step 3).
16Consult the AlwaysUp FAQ for answers to commonly
asked questions and troubleshooting tips.
Contact us _at_ 9914641983 and we are CBitss
Technologies and provide PHP training in
Chandigarh. We will be happy to help!
Address sector 34a, sco 23-24-25, 2nd floor,
Chandigarh, 160022.