fork conditionnel

This commit is contained in:
Rodolphe Quiedeville 2005-11-10 08:51:49 +00:00
parent 39a9f75b4e
commit 72481f4eeb

View File

@ -26,9 +26,7 @@
require ("../../master.inc.php"); require ("../../master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/ProcessGraphContrats.class.php"); require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/ProcessGraphContrats.class.php");
$childrenTotal = 6; $verbose = 0;
$childrenNow = 0;
$clientPerChild = 0;
$sql = "SELECT max(rowid)"; $sql = "SELECT max(rowid)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat"; $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat";
@ -36,29 +34,44 @@ $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat";
if ($db->query($sql)) if ($db->query($sql))
{ {
$row = $db->fetch_row(); $row = $db->fetch_row();
$clientPerChild = ceil($row[0] / $childrenTotal); $maxid = $row[0];
$db->free(); $db->free();
} }
while ( $childrenNow < $childrenTotal ) $fork = 0;
if ($fork == 0)
{ {
$process = new ProcessGraphContrats( 0, $maxid, $verbose );
$process->go(0, $verbose);
}
else
{
$childrenTotal = 6;
$childrenNow = 0;
$clientPerChild = 0;
$pid = pcntl_fork(); $clientPerChild = ceil($row[0] / $childrenTotal);
if ( $pid == -1 ) while ( $childrenNow < $childrenTotal )
{ {
die( "error\n" );
} $pid = pcntl_fork();
elseif ( $pid == 0 )
{ if ( $pid == -1 )
$childrenNow++; {
} die( "error\n" );
else }
{ elseif ( $pid == 0 )
$process = new ProcessGraphContrats( $childrenNow, $clientPerChild ); {
$process->go(); $childrenNow++;
die(); }
else
{
$process = new ProcessGraphContrats( $childrenNow, $clientPerChild, $verbose );
$process->go(0, $verbose);
die();
}
} }
} }
?> ?>