pcntl functions and database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I'm trying to work out threaded apps and I'm trying to use the pcntl
functions.

I can get it working ok without using a database but when I plug the
database in I get 'lost connection during query' errors.

Does anyone have any suggestions or a working example ?

Thanks!

My code:

<?php
declare(ticks=1);
$time = time();

if (!$connection_result = mysql_connect('localhost', 'root')) {
    echo 'Unable to connect: ' . mysql_error() . "\n";
    exit();
}

echo "Connected ok\n";

$childcount = 0;
$childrencount = 2;
while($childcount < $childrencount) {
    $pid = pcntl_fork();

    if ( $pid == -1 ) {
        die("error\n");
    }

    if ($pid == 0) {
        $childcount++;
        pcntl_wait($status);
        continue;
    }

    $qry = "select version() AS version";
    $result = mysql_query($qry);
    if (!$result) {
        echo "error: " . mysql_error() . "\n";
    } else {
        $row = mysql_fetch_assoc($result);
        echo $row['version'] . "\n";
    }
    exit();
}

echo 'took ' . (time() - $time) . ' seconds' . "\n";
?>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux