473,767 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3105
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_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
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_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
>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_cont ents($descripto rspec[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*******@attgl obal.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
5852
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 $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child
0
2293
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 to be the right thing to use but I have the problem that the called program gives >8kb data on both stdout/stderr back which causes my PHP script to simply hang in the fread call. To be precise the first 4096 "O" characters are read and displayed. ...
0
1669
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 from the php website which looks something like copied below... Since I can not find very good documentation on this function my question is: I suppose that the problem is with this 2 => array("file", "error-output.txt", "w") // stderr is a file...
2
2899
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 segment prot after reloc: Permission denied" Im running php 4.3.11 on fedora 3. Here is the method i've been debugging. It should just run '/usr/bin/gpg --version' and display the
2
3204
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 this? Below is a code snippet (which may or may not help). Thanks, -r
4
4563
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 work. Any ideas? For more detail on what I'm trying to do, its' something like this... -------------------------------------
2
4038
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 returns a successful exit value, and I can read the results it prints to STDOUT in PHP, but the perl script does not see STDIN from PHP. Since I want to use the perl script as a filter and I don't want to create an intermediary file, this is problematic....
6
5475
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 22050 -y /home/transla1/public_html/cybertube/web/uploads/video/ generated/31_70_AK000005.AVI.flv '; //exec($str); runExternal($str,$code); echo $code ;
1
6275
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 http://stackoverflow.com/questions/196771/what-is-the-best-way-to-escape-python-strings-in-php when i made following py script. print 'enter value' input = raw_input() print input
0
10169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10013
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9841
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8838
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7383
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.