Page 1 of 1

proc_open print all errors

Posted: Thu May 08, 2008 5:12 am
by sakismat
please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end

Code: Select all

#!/usr/bin/php
<?php
    
    $con = mysql_connect("localhost", "user");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("database");
    
    $query1 = mysql_query ("select sid, sip, sport, sname from stores");
    
    $reads = array();
    $storess = array();
    while ( $store = mysql_fetch_assoc($query1)) 
    {
        $storess[$store['sid']] = $store; 
        
        $ip = $store['sip'];
        $port = $store['sport '];
        
        $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("pipe", "w") // stderr 
        );
        
        $proc[$i] = proc_open('mysqldump -u user -pPASS -h '.$ip.' -P '.$port.' ... > file.sql', $descriptorspec, $pipes);  
        
                //get stderr 
        $reads[$store['sid']] = $pipes[2];
        
    }//end while
    
    echo "Dumping ...". "\n";
    
    
    /*
        echo "ALL STDERR"
        */
    
 
    
    
    echo "--OK--". "\n";
?>

I tried this:

Code: Select all

 
while ( stream_select($select_reads, $null, $null, 0) !== false ) 
    {
            
        
        echo "stream is \n";
        var_dump($select_reads);
        foreach ($select_reads as $read) {
            $sid = array_search($read, $reads);
            
            echo $storess[$sid]['sname'] . " SAID:\n";
            var_dump(fread($read, 1024));           
        }
 
        // stream_select modifies the contents of $select_reads
                // in a loop we should replace it with the original
        $select_reads = $reads;
        sleep(1);
    }//end while