NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: Safely running root commands

Hans Zaunere lists at zaunere.com
Mon Feb 28 09:07:59 EST 2005


> > 3) is probably the safest if written well, but then there lies the
> > trick :)  For complex root operations, like filesystem stuff,
> 
> Nothing that complex.  What I'm doing is manipulating the mail queue:
> viewing, deleting and holding email.  Not all that dangerous, but email

Not dangerous?  Check how many sendmail and other mail queue related bugs there have been in the last years - it's up there :)

As I mentioned originally, I'd go with a daemon then, and yeah, in PHP - there's no reason not to.  Something like this to get you started:


function daemonize() {

   $pid = pcntl_fork();

   if( $pid < 0 )
      return NULL;

   if( $pid )
      exit(1);

   posix_setsid();

   $pid = pcntl_fork();

   if( $pid < 0 )
      return NULL;

   if( $pid )
      exit(1);

   return posix_getpid();
}


---
Hans Zaunere
President, Founder

New York PHP
http://www.nyphp.org

AMP Technology
Supporting Apache, MySQL and PHP







More information about the talk mailing list