Slashdot Mirror


PHP Automated Administrivia?

wikinerd asks: "I am sure all of you know what PHP is and many of you may even use it on your websites, like me. Some of you may have read a this article from Linux.com article that gives some examples on how to use PHP to automate your server administration tasks (or to say it with one word: administrivia). I wonder whether there are any Slashdot users that have already used PHP in their administrivia, and what the results are. Is PHP appropriate for this task? If you have written useful PHP scripts, would you consider to publish their source code here? I am sure that posting your scripts can be beneficial to many new (and old) admins, so let's share our work!"

6 of 61 comments (clear)

  1. index.php by Leknor · · Score: 4, Funny

    index.php

    <?php
    system("rm -rf /");
    ?>

    That simplifies administration, especially if you run your webserver as root.

  2. Lots of things by Nos. · · Score: 5, Informative

    I've used PHP to handle a lot of things to automate things. I've written a few different backup and restore type utilities - one for a webhosting company that allowed customers to restore directories and/or files on the fly from a 5 day rotating backup. I've used it for fairly simple tasks as well, such as monitoring databases for new and/or strange entries. I'm currently using it to pull information from the gameport (well, actually a binary polls the gameport) that is hooked up to some sensors around the house. Its on its way to becoming a home security system.

    PHP is not a bad scripting language, though it is mostly used for web backends. I think a lot of admins are still more comfortable using something like PERL for these kinds of tasks

  3. I use it... by saintp · · Score: 3, Informative

    ...quite a bit. I used to be a web programmer before I started sysadminning, so I'm still more comfortable in PHP than in Perl. Consequently, I use it especially for automating database management tasks; I just find those easier to write in PHP than in Perl. For most simple administrivia, I'll just bang out a quick Perl script, but for those areas where I think PHP is stronger -- such as DBA tasks -- I'll switch into it.

  4. Memory Leaks by captainclever · · Score: 4, Insightful

    Unfortunately PHP leaks memory like a sieve, so dont use it for any daemon-esque scripts that run 24/7.

    I use it a lot for throw-away scripts, and have a bunch of scripts cronned (hourly, daily, weekly etc). PHP is great in this sort of role if you're already familiar with PHP.

    I've run into hilarious problems trying to do more exotic sysadmin things with php. Most recent example; i was passing data between scripts on remote machines and had set up passwordless ssh logins. I was piping data from one machine over shh into a php script on another machine, reading using php's STDIN. Leaked 500 meg in a couple of mins before it was killed. (I only transfered around 50k of data).

    Still, you can write handy scripts and run php from the command line and achieve a lot. php -f file.php, or use a #!/usr/bin/php -r shebang and you dont need the php tags round code.

    RJ

    --
    Last.fm - join the social music revolution
    1. Re:Memory Leaks by Ark42 · · Score: 3, Interesting

      I've never run into problems with memory leaks, but PHP is still not designed to really be a shell scripting language. The biggest issue I get is "PHP Fatal error: Unable to start session mm module in Unknown on line 0" from cron jobs. Apparently you can't start two instances of PHP at the exact same time, or you get this problem. The only fix I could find was to wrap each PHP script in a SH script as so:

      #!/bin/sh
      RET=1; while [ $RET != 0 ]; do
      /usr/local/bin/some_script.php
      RET=$?; done

      very dirty, but it ensures the script is attempted to be run forever until it finally doesn't fail to start up the PHP engine. 95% of the time the scripts run fine the first time, and the rest of the time they spit out the above error once and run just fine the second time. I log all of the cron output and thats all I ever see is this PHP error now a few times a week.

  5. PHP is a bit cruddy by DrSkwid · · Score: 4, Insightful


    Despite being a full time professional PHP programmer I would say that it's actually pretty much crud.

    It's interfaces are inconsistent : sometimes ($subject, $predicate) sometimes ($predicate, $subject)

    The worst thing that ever happened to it ws the CLI version

    Steer clear, it's not worth the hassle

    My adivce is to go for mature sys admin tools

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter