473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

proc_open print stderr

please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. $con = mysql_connect("localhost", "user");
  5. if (!$con)
  6. {
  7. die('Could not connect: ' . mysql_error());
  8. }
  9. mysql_select_db("database");
  10.  
  11. $stores = mysql_num_rows(mysql_query ("select * from stores"));
  12.  
  13. $query1 = mysql_query ("select sid, sip, sport, sname from stores");
  14.  
  15. $reads = array();
  16. $storess = array();
  17. while ( $store = mysql_fetch_assoc($query1))
  18. {
  19. $storess[$store['sid']] = $store;
  20.  
  21. $ip = $store['sip'];
  22. $port = $store['sport '];
  23.  
  24. $descriptorspec = array(
  25. 0 =array("pipe", "r"),  // stdin is a pipe that the child will
  26. read from
  27. 1 =array("pipe", "w"),  // stdout is a pipe that the child will
  28. write to
  29. 2 =array("pipe", "w") // stderr
  30. );
  31.  
  32. $proc[$i] = proc_open('mysqldump -u user -pPASS -h '.$ip.' -P '.
  33. $port.' ... file.sql', $descriptorspec, $pipes);
  34.  
  35. //get stderr
  36. $reads[$store['sid']] = $pipes[2];
  37.  
  38. }//end while
  39.  
  40. echo "Dumping ...". "\n";
  41.  
  42.  
  43. /*
  44. echo "ALL STDERR"
  45. */
  46.  
  47.  
  48.  
  49.  
  50. echo "--OK--". "\n";
  51. ?>
  52.  

I tried this:

Expand|Select|Wrap|Line Numbers
  1. while ( stream_select($select_reads, $null, $null, 0) !== false )
  2. {
  3.  
  4.  
  5. echo "stream is \n";
  6. var_dump($select_reads);
  7. foreach ($select_reads as $read) {
  8. $sid = array_search($read, $reads);
  9.  
  10. echo $storess[$sid]['sname'] . " SAID:\n";
  11. var_dump(fread($read, 1024));
  12. }
  13.  
  14. // stream_select modifies the contents of $select_reads
  15. // in a loop we should replace it with the original
  16. $select_reads = $reads;
  17. sleep(1);
  18. }//end while
  19.  
Jun 2 '08 #1
5 3082
sa******@gmail.com schreef:
please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end
Hi,

I cannot help you with your STDERR, but I spotted something that could
potentially slow down your script a lot.
[code]
#!/usr/bin/php
<?php

$con = mysql_connect("localhost", "user");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database");

$stores = mysql_num_rows(mysql_query ("select * from stores"));
Just a small suggestion:
The above line is a waste of CPU cycles (and bandwidth is mySQL is on
another fysical server).
You actually ask mysql to return the full content of the table stores,
only to find out how many there are.
This won't matter a lot when table stores is small, but it is a bad
approach, I think.
MySQL must:
1) Find out what * translates to (all your columnnames).
2) Send the full content of that table to PHP.

Much better is to use the SQL build-in command COUNT() for this:
$SQL = "SELECT COUNT(*) AS numrowsstore FROM stores;";
or
$SQL = "SELECT COUNT(storeid) AS numrowsstore FROM stores;";
(assuming storeid exists)

Just a suggestion. :-)

I hope somebody else can help you with the STDERR.

Regards,
Erwin Moller
Jun 2 '08 #2
On 8 May, 12:06, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
sakis...@gmail.com schreef:
please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end

Hi,

I cannot help you with your STDERR, but I spotted something that could
potentially slow down your script a lot.
[code]
#!/usr/bin/php
<?php
$con = mysql_connect("localhost", "user");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database");
$stores = mysql_num_rows(mysql_query ("select * from stores"));

Just a small suggestion:
The above line is a waste of CPU cycles (and bandwidth is mySQL is on
another fysical server).
You actually ask mysql to return the full content of the table stores,
only to find out how many there are.
This won't matter a lot when table stores is small, but it is a bad
approach, I think.
MySQL must:
1) Find out what * translates to (all your columnnames).
2) Send the full content of that table to PHP.

Much better is to use the SQL build-in command COUNT() for this:
$SQL = "SELECT COUNT(*) AS numrowsstore FROM stores;";
or
$SQL = "SELECT COUNT(storeid) AS numrowsstore FROM stores;";
(assuming storeid exists)

Just a suggestion. :-)

I hope somebody else can help you with the STDERR.

Regards,
Erwin Moller
What is more to the point, is that the value $stores is never used
again.
Jun 2 '08 #3
Captain Paralytic schreef:
On 8 May, 12:06, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>sakis...@gmail.com schreef:
>>please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end
Hi,

I cannot help you with your STDERR, but I spotted something that could
potentially slow down your script a lot.
>>[code]
#!/usr/bin/php
<?php
$con = mysql_connect("localhost", "user");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database");
$stores = mysql_num_rows(mysql_query ("select * from stores"));
Just a small suggestion:
The above line is a waste of CPU cycles (and bandwidth is mySQL is on
another fysical server).
You actually ask mysql to return the full content of the table stores,
only to find out how many there are.
This won't matter a lot when table stores is small, but it is a bad
approach, I think.
MySQL must:
1) Find out what * translates to (all your columnnames).
2) Send the full content of that table to PHP.

Much better is to use the SQL build-in command COUNT() for this:
$SQL = "SELECT COUNT(*) AS numrowsstore FROM stores;";
or
$SQL = "SELECT COUNT(storeid) AS numrowsstore FROM stores;";
(assuming storeid exists)

Just a suggestion. :-)

I hope somebody else can help you with the STDERR.

Regards,
Erwin Moller

What is more to the point, is that the value $stores is never used
again.
LOL, yes. Good point.
That makes it an even better waste of CPU. ;-)

Regards,
Erwin Moller
Jun 2 '08 #4
sa******@gmail.com wrote:
please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/php
  2. <?php
  3.     $con = mysql_connect("localhost", "user");
  4.     if (!$con)
  5.       {
  6.          die('Could not connect: ' . mysql_error());
  7.      }
  8.      mysql_select_db("database");
  9.      $stores = mysql_num_rows(mysql_query ("select * from stores"));
  10.     $query1 = mysql_query ("select sid, sip, sport, sname from stores");
  11.     $reads = array();
  12.     $storess = array();
  13.     while ( $store = mysql_fetch_assoc($query1))
  14.     {
  15.         $storess[$store['sid']] = $store;
  16.         $ip = $store['sip'];
  17.         $port = $store['sport '];
  18.         $descriptorspec = array(
  19.                0 =array("pipe", "r"),  // stdin is a pipe that the child will
  20. read from
  21.              1 =array("pipe", "w"),  // stdout is a pipe that the child will
  22. write to
  23.                2 =array("pipe", "w") // stderr
  24.         );
  25.         $proc[$i] = proc_open('mysqldump -u user -pPASS -h '.$ip.' -P '.
  26. $port.' ... file.sql', $descriptorspec, $pipes);
  27.                 //get stderr
  28.         $reads[$store['sid']] = $pipes[2];
  29.     }//end while
  30.     echo "Dumping ...". "\n";
  31.     /*
  32.         echo "ALL STDERR"
  33.         */
  34.     echo "--OK--". "\n";
  35. ?>
  36.  


I tried this:

Expand|Select|Wrap|Line Numbers
  1. while ( stream_select($select_reads, $null, $null, 0) !== false )
  2.     {
  3.         echo "stream is \n";
  4.         var_dump($select_reads);
  5.         foreach ($select_reads as $read) {
  6.             $sid = array_search($read, $reads);
  7.             echo $storess[$sid]['sname'] . " SAID:\n";
  8.             var_dump(fread($read, 1024));
  9.         }
  10.         // stream_select modifies the contents of $select_reads
  11.                 // in a loop we should replace it with the original
  12.            $select_reads = $reads;
  13.            sleep(1);
  14.     }//end while
  15.  
You read from your stderr pipe. In this case you could use:

echo stream_get_contents($descriptorspec[2]);

But you have an error in your proc_open call. You cannot use the
redirection symbols '<' or '>' (or the pipe symbol '|'). These are
handled by the command processor, which does not get executed when you
call proc_open.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #5
On May 8, 2:07 pm, sakis...@gmail.com wrote:
please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/php
  2. <?php
  3.         $con = mysql_connect("localhost", "user");
  4.         if (!$con)
  5.         {
  6.                 die('Could not connect: ' . mysql_error());
  7.         }
  8.         mysql_select_db("database");
  9.         $stores = mysql_num_rows(mysql_query ("select * from stores"));
  10.         $query1 = mysql_query ("select sid, sip, sport, sname from stores");
  11.         $reads = array();
  12.         $storess = array();
  13.         while ( $store = mysql_fetch_assoc($query1))
  14.         {
  15.                 $storess[$store['sid']] = $store;
  16.                 $ip = $store['sip'];
  17.                 $port = $store['sport '];
  18.                 $descriptorspec = array(
  19.                         0 =array("pipe", "r"),  // stdin is a pipe that the child will
  20. read from
  21.                         1 =array("pipe", "w"),  // stdout is a pipe that the child will
  22. write to
  23.                         2 =array("pipe", "w") // stderr
  24.                 );
  25.                 $proc[$i] = proc_open('mysqldump -u user -pPASS -h '.$ip.' -P '.
  26. $port.' ... file.sql', $descriptorspec, $pipes);
  27.                 //get stderr
  28.                 $reads[$store['sid']] = $pipes[2];
  29.         }//end while
  30.         echo "Dumping ...". "\n";
  31.         /*
  32.         echo "ALL STDERR"
  33.         */
  34.         echo "--OK--". "\n";
  35. ?>
  36.  

I tried this:

Expand|Select|Wrap|Line Numbers
  1. while ( stream_select($select_reads, $null, $null, 0) !== false )
  2.         {
  3.                 echo "stream is \n";
  4.                 var_dump($select_reads);
  5.                 foreach ($select_reads as $read) {
  6.                         $sid = array_search($read, $reads);
  7.                         echo $storess[$sid]['sname'] . " SAID:\n";
  8.                         var_dump(fread($read, 1024));
  9.                 }
  10.                 // stream_select modifies the contents of $select_reads
  11.                 // in a loop we should replace it with the original
  12.                 $select_reads = $reads;
  13.                 sleep(1);
  14.         }//end while
  15.  
there is an other solution:
sending stderr to file

Expand|Select|Wrap|Line Numbers
  1. $descriptorspec = array(
  2. 0 =array("pipe", "r"),  // stdin is a pipe
  3. that the child will
  4. read from
  5. 1 =array("pipe", "w"),  // stdout is a pipe
  6. that the child will
  7. write to
  8. 2 =array("file", "/tmp/error-output.txt",
  9. "a") // stderr is a file to write to
  10. );
  11.  
but the problem is: who to add to the file the "sname" to know from
which store came the stderr ?
thank you
Jun 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
0
by: Christian Hammers | last post by:
Hello I would like to call a unix shellscript from within a PHP script and - write data to its STDIN - read data from its STDOUT *and* STDERR - get its exit code afterwards proc_open seems...
0
by: Muffinman | last post by:
Howdy, For a script I need the exact output of the apache htdbm.exe to a var so I can extract all users from a database. Now I found out that this can be done with Proc_open. I got this script...
2
by: razorfold | last post by:
Hi, I've been trying to run gpg through proc_open() and have failed all weekend. I keep getting this error from stderr: "/usr/bin/gpg: error while loading shared libraries: cannot restore...
2
by: razorfold | last post by:
Hi, I've written something that takes text and passes it to gpg to encrypt. It works great except when the text size is greater than 64k at which point PHP/Apache hangs. Is there any way around...
4
by: darrin.skinner | last post by:
Hi all, How can I open a file/pipe to something other than STDOUT/STDERR? I.e. I want to write to file descriptor # 3. fopen("php://std3"... does not work. fopen("/dev/ttyS3"... does not...
2
by: kimonp | last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki. I am trying to call a perl function from within php using proc_open. The perl script is being executed and...
6
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar...
1
by: YasirHussain | last post by:
hi! i want to execute a python script from php through proc_open() function of php.. i read a fine tutorial at ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.