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 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
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.
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 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_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
=============== ===
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
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child
|
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.
...
|
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...
|
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
|
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
| |
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...
-------------------------------------
|
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....
|
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 ;
|
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
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |