Popen Returns Output After Delay?

Jun 26, 2011

I am executing FFMPEG with popen() to get the result of the process. The main reason I am doing this is so I can stream constant output and build a progress bar. The issue is that the process starts and I receive some initial information. The rest of the information does not appear until after the process is done however. So essentially, the rest of the output (output on the progress) which comes on intervals when the process is going is delayed right before the process and all comes at once after the process is done which is useless. I need the output to constantly come so I can update a progress bar. If I change 2>&1 to 2> stderr.txt that text file receives output consistently but I would like to receive in php since many processes may be running. Anyone have any ideas on solving this? It seems noone can figure this out...and it is driving me crazy! IF anyone helps me figure this out (and actually solve it)


View 1 Replies


Popen Only Returns Partial Output?

I am using popen to execute a command and the problem is that I only get output immediately at the start (entries go in my database) when the script executes, and after it is finished which makes no sense to me. I am trying to get it so that input is constantly going into my database along the way when the popen process is working.

$handle = popen ('/usr/local/bin/ffmpeg -i /home/g/Desktop/cave.wmv ' .
'-deinterlace -acodec libfaac -ab 96k -ar 44100 -vcodec libx264 ' .
'-s 480x320 -f flv /home/g/Desktop/file.flv 2>&1', 'r');[code].....

View 1 Replies

Popen() Output To A File?

I have a linux binary that I run from a webpage which produces a lot of output and I would like to send that to a file, but nothing seems to work here is an example.. It does however send it all to the httpd "error_log" file

popen("/home/mybinaryfile > output.file", "w");

View 2 Replies

Popen And Proc_open Not Returning Binary Output?

When using popen or proc_open to run the following command to list the contents of a windows share:

smbclient -N -U 'username%password' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -d 0 '//server/sharename' -c 'dir "dirpath*"' 2>/dev/null

If the file in the share has the § character (ASCII 21 Decimal) when it encounters the special character it skips data until the next line.

$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "wb"), // stdout is a pipe that the child will write to


View 1 Replies

Email - Reasons For Popen Command To Fail / Error @$mail = Popen($sendmail, "w")?

I have a batch email process that sends about 30,000 email messages. I have ran into a strange problem where it gets to about 85% completion of the process and then the email start failing with the message Could not execute: /usr/sbin/sendmail I am using a library called PHPMailer 1.73 and the relevant code where the error message comes from is

if(!@$mail = popen($sendmail, "w"))
$this->SetError($this->Lang("execute") . $this->Sendmail);
return false;

The value of $sendmail is of the form: /usr/sbin/sendmail -oi -f support1@example.com -t

I have set_time_limit(0); so the script will not timeout.

Is there anyway to figure out why all of a sudden popen() starts failing? Could the OS be running out of file descriptors or some other limit being reached?

How should I resolve this? Should I have it sleep and then retry the popen() several times before failing?

Update: Thanks to the suggestion of Marko to check out proc_open() I found on the proc_open documentation a comment that if it returns FALSE it probably means that you ran out of file descriptors or you are out of memory. I found that my process was taking 20G of memory. But how could it take that much memory if memory_limit is set at 64M? Well, it seems that running external programs with exec(), popen() or proc_open() do NOT count against PHP's memory limit. See this SO question for more info on that, Debugging memory usage in mod_php. I'm still not sure how this is happening but I suspect some sort of memory leak.

In summary, popen() and proc_open() can return FALSE if you are out of file descriptors or out of memory.

View 1 Replies

Delay The Output Of Headers Until The Entire Script Has Been Run?

It is possible to delay the output of the headers to the browser until the entire php script has finished executing?

View 2 Replies

Set Mail Delay At A Random Time Delay Of 1-20 Seconds?

Trying to set mail delay at a random time delay of 1-20 seconds between each output. simply put: send, delay for x-seconds, send, delay x-sec., repeat

Here is the code I used to try to adjust it, but it's not working correctly, it's still sending normally. One every 10 seconds.

if (!$delaySecs) {
!$delaySecs = $numbers;
$number = range(1,20);
$numbers = array($number);
foreach ($numbers as $number)
echo "$number ";

View 1 Replies

System() Returns The Last Line Of Output Twice

I am running php v 5.0.0 on a redhat box. I have a php script in a
file called p_script_1. I have another small script in file
p_script_2. p_script_1 calles p_script_2 through a system() call. THe
last line of the output from p_script_2 is duplicated. As a test I ran

php -E 'echo system ("ls ");'

<you have to hit ^D after you hit newline>. Anyway, this simple "ls"
is also duplicating the last line of output. Is this a bug or feature?

just got access to a brand new, up to date RedHat box running php
5.1.4 and it is happening there too.

View 3 Replies

Remove Carriage Returns From Output Of String?

I am using wordpress as a CMS and trying to allow user fields to be input to populate the info windows in a Google Map script. I am using this to select the id and pull in the content from a custom field.

It works fine unless there is any html in the custom-field which breaks the script.
I looked at htmlspcialchar and htmlentities but rather than strip everything out I would like to have it escaped so it still works and the html is intact. Any suggestions? I am pretty new to PHP and would really appreciate any pointers.

After a while I am still unable to find a great solution for this. TheDeadMedic suggested I use esc_js

but that printed all of the actual html code instead of rendering it. Something else I tried was to use the trim function.. this is where I am at now where it works as long as no in the output. The $snip string, mapExcerpt field is where the returns are coming from:

<?php $post_id = 207; // Wordpress Post ID
$my_post = get_post($post_id);
$mapTitle = $my_post->post_title;
$mapIMG = get_post_meta($post_id, 'mapImage', true);


View 5 Replies

How To Remove (replace) Carriage Returns In Output Code..

Let's say I have a line of code in a MySQL table as following:

This is some text in a database table with a carriage
return in the middle of it!

Now, if I grab that code and echo it, the text will show up in the browser with no line break, which is fine. HOWEVER, if you look at the page source for that code, there is still the carriage return in the middle of the line. My question is, how can I remove that carriage return from the text in the source code.

View 8 Replies

Regarding The Popen()

I'd like to understand the general idea of the popen(). The terms I could not get by reading the manual are:

"Process File Pointer"

I'm not sure why string mode is required to run a script in the background. What is the difference between the followings? Both just fork the $script, don't they: PHP Code:

popen("php -f $script", "r");

PHP Code:

exec("php -f $script > /dev/null &");.

View 1 Replies

GPG With Popen Instead Of Exec

I am the Team lead for the GPG plugin for Squirrelmail.


We use exec for all of our gpg program executions, but this requires doing "echo $plaintext | gpg $commandflags"

This works fine, but means that some plaintext is passed on the command line, and could be visible to an attacker monitoring process execution on the machine the web/php server is running on.

It would be more secure to use pipes. gpg supports the '--command-fd (pipe)' and '--status-fd (pipe)' command flags to take commands and report status from a pipe, but I can't figure out how to use php to pass the correct pipe descriptors to the command line. On the command line, the pipes 0,1, and 2 correspond to stdin, stdout, and stderr, respectively.

In theory, we should be able to use popen to open one read and one write pipe, and then pass the write pipe to --command-fd and the read pipe to --status-fd. Because Squirrelmail is used on servers of all different environments, I can't assume that the w+ flag will work with popen. I also can't require PHP 4.3.0 or higher, which would allow us to use proc_open.

Really, I want to avoid passing any plaintext on the command line, or writing anything to temp files, both of which introduce security risks.

View 1 Replies

Popen() Fuction Has Been Disabled

I tried to install the uploadprogress PECL package using the PEAR Package Manager, and I got the following error message:

Warning: popen() has been disabled for security reasons in URL] on line 440

So it appears that the popen function failed because it is listed in the disable_functions directive in the configuration file (php.ini).

I'm in a shared environment, and my hosting company won't enable popen. I also don't have shell access - just FTP. Does anyone know how I can install a PECL package with popen disabled?

I'm using PHP 5.2.9 on Debian GNU/Linux 4 on Apache 2.0.54.

View 3 Replies

Popen() Fuction Has Been Disabled?

I'm trying to install the uploadprogress PECL package using the PEAR Package Manager, but I keep getting the following error:

Warning: popen() has been disabled for security reasons in [url].....

It appears that the popen function failed because it is listed in the disable_functions directive in the configuration file (php.ini).I'm in a shared environment, and my hosting company won't enable popen. I also don't have shell access - just FTP. Does anyone know how I can install a PECL package with popen disabled?

View 4 Replies

Killing Processes Opened With Popen()?

I'm opening a long-running process with popen(). For debugging, I'd like to terminate the process before it has completed. Calling pclose() just blocks until the child completes.How can I kill the process? I don't see any easy way to get the pid out of the resource that popen() returns so that I can send it a signal.

I suppose I could do something kludgey and try to fudge the pid into the output using some sort of command-line hackery...

View 3 Replies

Alternative For Popen() Which Works On Win/unix ?

I have problem with using popen() on linux. On windows this code runs ok

Code: [Select]<?php
popen('E:phpphp.exe E:wwwscr.php','r');

But when i try on linux

Code: [Select]<?php
popen('php /home/www/scr.php','r');

Its simply doesnt work.Even if i try with full PHP path.. Also every alternative for popen() which works on win/unix is welcome.

View 4 Replies

Popen - Command Line Vs. Web Server Performance

say i have the following two php scripts:

$p1 = popen("c:phpphp -q hello.php","r");
$p2 = popen("c:phpphp -q hello.php","r");
while (!feof($p1))
print fgets($p1);
while (!feof($p2))
print fgets($p2);


print "hello,

when i run ptest.php via the command line (ie. by typing in c:phpphp
ptest.php at the dos prompt) it runs instantly.

when i run ptest.php via a webserver, the resultant page not only
doesn't even load - it results in a bunch of errors (that appear as
dialogue boxes on the machine doing the hosting) effectively saying
that the command failed to execute properly and will now be shut down.
after clicking through all the errors, the systems performance is
noticebly affected (and in fact is bad enough such that i think a
reboot is justified).

View 4 Replies

Php Or Apache? Exec, Popen, System And Proc_open Commands Do Not Execute Any Command?

but i´m starting to think that the problem is with apache and not php? i tried to run a pythonscript that is actually what i´m going to run in the end, then it seems to run but stops when the script tries to access a txt file looking like this

[stdout] =>
[stderr] => Traceback (most recent call last):
File "pythontest.py", line 4, in ? f = open("(path)/temp.txt", "w")
IOError: [Errno 13] Permission denied: '(path)/temp.txt'

I have tried all different kind of execution methods that i could find exec, system, popen, proc_open almost nothing runs, i can get a string from system("pwd") but system("ls") returns a number 127 or 126. I also tried to run a compiled c program (code below) exec will return an object "Array" but system will only return 127 or 126 as ls does.


View 3 Replies

Subquery Returns NULL - Yet Returns Proper Value On Localhost

Couldn't get into my old account so my first post on my new account Edit: I guess I got into the old account again automatically by email address, If got a query which works like a charm on my localhost but on the live server it won't work as nice

series.sID AS sID,
series.description AS seriename,
(SELECT sum(images.price) FROM images WHERE images.sID = 1) AS seriestotal,
GROUP_CONCAT(DISTINCT themes.description ORDER BY themes.description ASC SEPARATOR ', ') AS themes,

Now on my localhost it returns the sum of all price fields, on the live server it returns NULL as seriestotal but no further errors or anyting. The site and database on my live server are an exact copy of my local site and database. My local MYSQL version is 5.0.67 On the live server it's 4.1.10 Yet I thought subqueries are support from 4.1 onwards... I've tested another simple query with a subquery on the live server and that works.

View 6 Replies

Query Returns With An Error Stating The Subquery Returns More Than 1 Row?

I am trying to perform a SQL query that acts in two parts.

First, I have a query that returns a list of 10 Ids.But then I want to have a SELECT statement which has a WHERE clause for each of these 10 ids.Is this possible?

I tried: SELECT * FROM tablenameWHERE id= (SELECT id FROM table_of_ids WHERE
tableid='1a177de1-3f25c9b7910b' OR
tableid='64faecca-133af807a65a' OR
... up to 10 Ids)

but it returns with an error stating the subquery returns more than 1 row.

Note, the tableid and id columns of table_of_ids are different values.

View 6 Replies

How Can I Delay Something By 10sec's

Anyone got any idea how I could delay part of a script being posted (echoed) for ten seconds ??

I know, I know, WHY would anyone want to delay something for ten seconds. Hows about....just because I do because I'm learning.

I'm sure it will have something to do with date or time or something, but I'm pretty brain dead at the moment.

View 4 Replies

Delay Page - How?

When my users type in a search parameter on my website, I want the search to
execute. While it's executing, I want a temporary page to be loaded, with
perhaps an advert, and when the search actually completes, the search
results are displayed.

It's like on orbitz or hotwire, when you search and they show you some
messages while it's searching.

Any clues on how I'd do that?

View 10 Replies

Display Delay

If i have a few quotes to display but i want them to appear each in a delay of a second after the one before, is it possible with PHP or i need to add java script?

View 1 Replies

Delay Function

I'd ask about delaying execution of php scripts on one page. I've tried: PHP Code:

<? sleep(10); ?>

example: PHP Code:

View 2 Replies

Ldap_connect() Delay

I have small problem with the ldap_connect() function, it is causing a 2.5-2.7 second delay every time it is called. What is strange is that anything can be passed as an argument, an LDAP server, or just a string of text, as the connection actually occurs at the ldap_bind() stage. The web server is run on a domain controller, so the LDAP server is local. Connecting to the LDAP server from a client machine does not produce a delay.

I've isolated the problem to PHP (versions 4.4.4, 4.4.7 and 5.2.3 are affected), as the same results can be reproduced with any LDAP server (or random text) and the server machine. Using PHP on other machines, or Python on the server are not affected by this.

Can anyone recommend any way to get some debug output from the ldap_connect() function?

View 5 Replies

PHP Delay Function?

Is there a function, or simple script that will delay processing by seconds, or whatever time I need? For example: PHP Code:


// wait 3 seconds to start the next script.......


// wait 3 seconds to start the next script.......


Any ideas?

View 8 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved