PHP Command Line Interface (CLI) Tips
I've been creating a php application that runs from the command line and I have a few tips that I've learned from my adventures.
- If you've installed php before, and reinstall it, make sure what version of php you are using from the command line by checking out your environment variables in windows. This happened to me today when I realized that I was actually using a version of PHP that I installed a year ago (and forgot about), and not the new WAMP version I just installed.
- Make sure you are using the right php.ini file. If you are using WAMP, then the php.ini file that apache uses is in the apache /bin folder (not the php.ini in wamp/php). The php cli will use the first php.ini it can find in the windows path environment variable. In my case, this was an old version in another php directory I set up. Once I deleted that, it used the version in the /wamp/php directory.
- You can use mail() on windows in the CLI -to set this up use the fake sendmail for windows hack. Make sure you set the php.ini settings both the php.ini that apache uses and the php.ini that the CLI uses (if they are different).
- Running applications from the CLI is fun because there is no maximum execution time. Just think of the possibilities. I'm writing a script that parses RSS feeds and searches for keywords in the titles. I can parse 1000 rss feeds in about 10 minutes using Magpie RSS. I'll post this script if anyone is interested.