Schedule with Dante and PHP

Many PHP programmers are comfortable with the Unix/Linux server world.  While PHP has certainly flourished as part of a LAMP stack, one must not forget it’s portability.  PHP melds well with a Unix tool chain of pipes.  Something that is often over looked is how it melds with a Windows environment.  What if you want to express your creativity with Internet applications, but find yourself working in a entirely Microsoft environment?  PHP should find its way high on your list of technologies.  What if you are already using PHP and have access to Windows servers?  You should be taking advantage in their hidden potential.

One of the features of the windows operating system that deserves exploiting is Task Scheduler 2.  Task Scheduler 2 was introduced on Windows Vista and Windows Server 2008.  At first glance you may just see Cron with a GUI.  It isn’t like they dedicated a Microsoft Certification to it and you would be hard pressed to find Task Scheduler training.  However Task Scheduler 2 is much more than run Foo at the given date and time.  You have a wide variety of triggers, conditions and options surrounding the execution of the given command.  Time being one trigger of many including immediate queuing.   This single ‘hidden’ potential could be reason enough to have a single Windows Server in your environment.  Fortunately for us Task Scheduler 2 comes with all versions of Windows desktop and server.  Licensing often being the pivot point in many IT organizations, Windows Webserver 2008 is a modest price and does come with the two important pieces we will be taking a look at now.  That is: Task Scheduler 2 and IIS.

From a programmers perspective, using a piece of technology as different as Task Scheduler and COM may seem to require more effort than they are worth.  Here is where I would like to introduce Dante Job Scheduler.  A project in development, Dante is meant as the broker to your Windows Server’s job scheduling and queuing abilities.  Dante is built on the Crossley Framework which contains a growing number of classes that wrap COM and .NET functionality.  You can easily take advantage of this  in your application.  For now, I would like to show you the early functionality built into Dante’s UI and Rest style application services.

To get started, download Dante, and uncompressed it on your computer running Windows  in a place you can point an IIS site at.  The directory structure is simple, but the one we will be concerned with first is called ‘public’.  Open Internet Information Services Manager and create a new site.  Use the path to the public directory as your value for the ‘Physical path’.

When you point your browser at the site, you will be prompted for a user name and password.  The easiest one to use is one for a known profile on the box. Administrator can work fine but you may want to consider creating a dedicated account for Dante.  If you are working on a development machine it would be great for the sake of this demo if you just logged in as the user you are logged in as now.  This will allow you to see things in action.

The first thing you see is a list of scheduled tasks that may already be there for that profile.  If you logged in with a regular user account you may see things like Google Update listed.  To create a new task click the Create tab at the top of the page.  In this form, you should give it a recognizable unique name.  Then in the ‘Command’ field, enter the path to notepad.exe (c:\Windows\notepad.exe worked for me).  Enter a run date of the present date, and then a time in the near future.  Click submit and then you can view it under the ‘List’ tab.

While you are waiting for it to run (it may not show up the second it is scheduled, it may need a second to show the GUI), click on some of the tasks to see their details.  You may notice the XML link at the bottom of the details list.  This is the XML definition of the task.  An application can create such an XML and pass it to the scheduler as a task envelop.  The ‘Run’ and ‘Stop’ links do just as you would assume: run and stop a executing task.

You can experiment on the task you just created.  Click the details of the task and click ‘Run’ to  see the notepad GUI appear.  Then Click the ‘Stop’ link to see it close.  Not overly exciting unless you understand the potential.  If you have Firebug running you may have noticed the XHR calls being made via jQuery.  Each of these can be imitated from a remote computer.  Say you want to run a task called “MyTest”  you would simply make a request for https://<username&gt;:<password>@<server_address>/tasks/run/MyTest.  The same can be said of creating a new task.  To create a task simply form a request with your favorite HTTP client to: https://<username&gt;:<password>@<server_address>/tasks/new/?tskname=<taskname>&cmd=<command>&rundate=<date>&runtime=<time>.

As mentioned before there are many triggers and options available in Task Scheduler 2.  Most of which will find their way into Dante and Crossley Framework.  Soon a client class will also be available to further simplify your development.  Exposing COM functionality with PHP takes some patience.  Even so, if you are running PHP on Windows, great benefits can be gleaned.

I hope this taste has peaked your interest.  If you are so motivated I encourage you to experiment with Dante and share your thoughts or even code.

Schedule with Dante and PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s