views:

410

answers:

6

What are the benefits of PHP's CLI over other scripting languages/environments such as VBScript or even windows scripting?

+6  A: 

One use would be as a scheduled maintenance task that is related to a web application. You will be able to use the libraries and functionality from the web app.

I guess another benefit is that if you are familiar with php web development, then hacking out a quick cli script in php may be a quick way to get something done quickly.

Zoredache
+3  A: 

We use the PHP CLI for cron tasks like sending out emails, closing old threads and sending out email queues across web servers. You can also use it for one-off projects like parsing a flat text file straight into your database. That's not something you want to be web viewable. These tasks have the advantage of sharing libraries you've built for your website such as database access and sending emails.

thrashr888
A: 

First thing that springs to mind is a PHP application that you could easily render as a daemon in conjunction with a task scheduler to constantly do certain updates because you can't/wouldn't want to depend on user activity to trigger the execution of the application - but you really don't need an interactive CLI for this sort of stuff, that is you could just use the available task scheduling tool through something other than a CLI and let it do all the dirty work.

The major reason would be PEAR, and I think this is when PHP starts getting really interesting. It's a must for symfony, but you can really see it help automate your work with a language your already familiar with - no need for learning python, perl, etc. and it's a plus that PEAR scripts don't have to reside in the cgi repository (some shared hosts are very restrictive).

kRON
A: 

All else being equal, use the language you know best. And for a lot of utility programming, all else is equal.

In most such cases, VBScript or Powerscript probably are at least as suitable.

le dorfier
A: 

Extending an otherwise web-only project to the commandline;

See how drush is extending drupal.

xkcd150
A: 

The best scripting language for a job is almost always the one you know best. So if you know PHP better than VBScript, that's going to be your biggest advantage. I have written a number of command line utilities and maintenance scripts that a lot of other people would probably write in PERL, BASH or even Python, but I simply don't know those languages nearly as well as I do PHP.

JamesArmes