Screen with bytes of info

RSS Feed
Technology Bytes

Run a PHP script directly

PHP Script

     I have been recently working on a project to get a script to run when my server receives an e-mail that is addressed to a particular address.  The idea is to parse out the e-mail that is received and do some operation based on the contents of the e-mail.  I have worked so much in PHP that I thought it would be good to use to handle the work I would like to be done.

     I have done this thing before using Postfix to handle the incoming mail and direct it to a script defined in the alias file.  Inside alias, it runs the PHP executable with the PHP script passed in as a parameter.  This is just fine and works well, but I noticed when doing some other research that it is possible to run a PHP script directly without calling the executable file.

     All that is required to run a PHP script (at least on *nix systems) is to place the #! and the location of the executable on the first line of the script:
Then just start the script as you would any other PHP script with the PHP tags and you're good to go!  Oh, don't forget to make the file executable by running chmod +x on the file.