I have reasonable knowledge of PHP, Perl, and Bash. I use Perl for most text processing on my system (find, replace, filter output, etc). I use PHP for web development, allowing a user to view and interact with database data via the browser. I use Bash for quick and dirty scripts often to supplement the more complex Perl scripts.

I'm a big believer of focusing on as few languages as possible (to get the job done) and becoming an expert in them.

So the question is, why not use PHP for the common tasks that Perl (and Bash) are used? Are there good reasons (limitations or features) why PHP is mostly used for web development, while Perl and Bash are mostly used for "offline" "scripting"?


Because Perl has a much more powerful feature set than PHP.

Perl is a more general programming language, and has much more text operations capabilities than PHP, and probably than any other language out there, and better OS interaction.

Perl has a powerful Regex native support, which means string manipulations at its best.

Also, Perl has been around for many years now, and offers a huge library of modules. Create complex scripts with Perl is easy; with the right modules you only need to write little lines of code.

You may want to take a look at this great answer which explains clearly the differences between the two languages.

|improve this answer|||||

For system scripting, shell scripts have better interaction with the OS. Its simpler to issue a command in a script rather than wrap that command in a function call in PHP.

That being said, there's no reason not to use PHP for various non-web applications, such as scheduled services/cron jobs that process data somehow (import/export/retrieve/etc). Its perfectly suitable for such tasks. I've been doing that for years. Like you said, there's no point in maintaining code in multiple languages if its not necessary.

|improve this answer|||||

These days with PCNTL and POSIX functions you can use PHP for scripting and do anything a Perl/Python/Bash script can. My company uses PHP heavily for scripting including some non-trival cases (e.g. custom queue management run as a system service) and it appears PHP is as reliable as Perl/Python/Bash scripts.

However OS support in PHP has improved quite recently. Some time ago it was horrible. IIRC you only had only basic "Program execution" functions with some bizzare limitations (no proc_open() so only one-way pipes with popen() and so on). At the same time you could enjoy Perl/Python many OS modules and achieve anything you wanted with ease.

|improve this answer|||||

I don't think there is any script you couldn't write in PHP.

Of course, Perl is specializied on administrative scripts.

But if your MO is using as little languages as possible, and you are already conversant with PHP, then use it. I don't think you'll miss any tools.

|improve this answer|||||

I think its mostly tradition and preference and when people are looking for examples of how to do X,Y,Z if it tends to be in bash/perl, then why rewrite just to use php.

|improve this answer|||||

I once was a network admin in a student dorm and came across a firewall configuration script a predecessor had written in PHP. I think this was very prospective of him. Some student doing a little admin work (like me) is much more likely to know some PHP than one of the GP scripting languages normally used here. So I was able to do necessary changes without having to handle a language I never used before. To be honest: When I later mentioned this script he admitted that it in some way was meant as a joke to utilize PHP in this way.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.