please help
how can I get stderr from processes ($proc[$i]) in my screen
without waiting the other processes to end -
#!/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"));
-
-
$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: -
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
-
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
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.
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 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
-
#!/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"));
-
$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:
-
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
-
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
==================
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
-
#!/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"));
-
$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:
-
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
-
there is an other solution:
sending stderr to file -
$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("file", "/tmp/error-output.txt",
-
"a") // stderr is a file to write to
-
);
-
but the problem is: who to add to the file the "sname" to know from
which store came the stderr ?
thank you This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 ...
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |