dman666 Posted June 19, 2009 Share Posted June 19, 2009 Greatings everyone. I have an issue with forks. What I am trying to accomplish is writing to an rrd database (arround 20000 entries) via the following php script. I have never used forks before and it seems that my rrd is not graphing. When I run a top on my gentoo linux box while I run this script I see a lot of defunct programs, but when my script finishes it says that the child exited gracefully. I don't know whats going on I hope you guys can help. If the code executes incorrectly and spawns a zombie process will linux just distroy the zombie or allow it the finish? Heres what I am trying to work with. this is from an Object that holds and polls snmp info. function somefunc { $pid = array(); //Using ID's grabbed from snmp poll as array id's foreach($this->LUID as $esn=>$id) { //Spawn new process $pid[$id] = pcntl_fork(); if($pid[$id]) { //display process info #print "Process forked ".$pid[$id]."\n"; } else if($pid[$id] ==-1) {} else { //Run child //this process returns an array of information from the snmp client $temp = $this->walk($id); print_r ($temp); //iterate and write to file foreach($temp as $key=>$data) { //writes to file $rrd = new objRRD($esn, $key, constant("rrd_path"), $this->name); $rrd = $rrd->update_rrd($data); } //exit the current script exit(); } } foreach($this->LUID as $esn=>$id) { //wait until the child is done. This is to handle flow control pcntl_waitpid($pid[$id], &$status); //display completion print $pid[$id]." complete.\n"; } } Link to comment https://forums.phpfreaks.com/topic/162963-forking-in-all-its-glory/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.