Article content

Making sure PHP-CGI is running (on Windows Server)

I recently had the pleasure of setting up a very old Windows 2003 server with Nginx and PHP-CGI. It works very well, and can serve a heap of concurrent clients with no problems, but every now and then, PHP-CGI terminates, which is a bit of bother. Here's a way of keeping a tab on it.

You obviously don't want to sit around paying attention to the system and restarting PHP-CGI manually, so here's a quick way of checking whether it's running, and start the process if it has been terminated. Permalink for this article http://mirror.magicode.org/content/Making_sure_PHPCGI_is_running_on_windows

  1. @echo off
  2. netstat -ban -p tcp > c:\netstatlog
  3. <"c:\netstatlog" find "php-cgi" >NUL 2>&1 &&echo OK >NUL ||RunHiddenConsole.exe C:\PHP\php-cgi.exe -b 127.0.0.1:9090
This text was originally written for http://blog.magicode.org

Save and run this bat-file as a cronjob on Windows (forget Scheduler, you need something that can run every minute) and you're set. Change the port for PHP if you're using something else than 9090 (9000 is the default for Nginx). If you see this notice on any site other than magicode.org, it's probably been lifted without consent

You've probably noticed that I'm executing a file called RunHiddenConsole.exe. This is a very small utility that will let you start any command silently. RunHiddenConsole.exe is freeware and open source, and is available here. There are many cron-like programs for Windows, I've had success with a freeware program called pycron.

Discussion
17.06.2009 22:15
Wouldn't it be nice if Microsoft made a decent shell for Windows? I know I can run third party stuff, but doesn't integrate well.Mike

Submit your comment

Text:

Your name:

Your email:

Show my mailaddress (spam protected)

Your website:

Show my website

Featured Article

PHP Variables and strings

A variable is a means of storing a value, such as a text string or a number. In PHP you do not have to declare your variable, as it's automatically declared when you set it. Since you do not need to declare the variable, you do not have to specify what kind of data it contains either.

Topics
Magicode's own open source project
From the forum / Latest comments
You may also want to to check out these links: sendanonmail.com, superstrongpassword.com.