<?php
/**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
*
* Base class for making daemons that can do several tasks in parallel.
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Daemon
- * @package Laconica
- * @author Zach Copley <zach@controlyourself.ca>
- * @author Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2009 Control Yourself, Inc.
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://laconi.ca/
+ * @link http://status.net/
*/
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
* Daemon able to spawn multiple child processes to do work in parallel
*
* @category Daemon
- * @package Laconica
- * @author Zach Copley <zach@controlyourself.ca>
- * @author Evan Prodromou <evan@controlyourself.ca>
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link http://laconi.ca/
+ * @link http://status.net/
*/
class ParallelizingDaemon extends Daemon
function run()
{
if (isset($this->_debug)) {
- echo $this->name() . " - debugging output enabled.\n";
+ echo $this->name() . " - Debugging output enabled.\n";
}
do {
if ($pid) {
// Parent
+
if (isset($this->_debug)) {
echo $this->name() .
- " (parent) forked new child - pid $pid.\n";
+ " - Forked new child - pid $pid.\n";
}
// Child
// Do something with each object
+
$this->childTask($o);
exit();
}
// Remove child from ps list as it finishes
+
while (($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) {
if (isset($this->_debug)) {
- echo $this->name() . " child $c finished.\n";
+ echo $this->name() . " - Child $c finished.\n";
}
$this->removePs($this->_children, $c);
}
// Wait! We have too many damn kids.
+
if (sizeof($this->_children) >= $this->_max_children) {
if (isset($this->_debug)) {
while (($c = pcntl_wait($status, WUNTRACED)) > 0) {
if (isset($this->_debug)) {
- echo $this->name() . " child $c finished.\n";
+ echo $this->name() . " - Child $c finished.\n";
}
$this->removePs($this->_children, $c);