473,396 Members | 2,010 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,396 software developers and data experts.

exec, run until finished

Hi

I call a program through exec that can take a long time to execute.
This is fine but I would like to show some kind of animation or
something while the program is running and when it is finished letting
the user download the file.

Right now I'm using code similar to this simplified example:

----- index.php -----
<form method="post" action="genetate.php" target="_blank">
<input type="submit" value="Generate!"/>
</form>

----- generate.php -----
<?php
$tmpname = time() . md5("bla");

// Writes to $tmpname
exec("takesalotoftime $tmpname");

$len = filesize("$tmpname");

header('Content-type: application/postscript\r\n');
header("Content-Length: $len;\r\n");
header('Content-Disposition: attachment; filename="' . $tmpname
.. '"\r\n');

readfile("$tmpname");
?>

So what is the best way to start the exec, show an animation until it
is finished and then send the file to the user?

Jan 1 '07 #1
4 3580
An************@gmail.com wrote:
Hi

I call a program through exec that can take a long time to execute.
This is fine but I would like to show some kind of animation or
something while the program is running and when it is finished letting
the user download the file.

Right now I'm using code similar to this simplified example:

----- index.php -----
<form method="post" action="genetate.php" target="_blank">
<input type="submit" value="Generate!"/>
</form>

----- generate.php -----
<?php
$tmpname = time() . md5("bla");

// Writes to $tmpname
exec("takesalotoftime $tmpname");

$len = filesize("$tmpname");

header('Content-type: application/postscript\r\n');
header("Content-Length: $len;\r\n");
header('Content-Disposition: attachment; filename="' . $tmpname
. '"\r\n');

readfile("$tmpname");
?>

So what is the best way to start the exec, show an animation until it
is finished and then send the file to the user?
You won't be able to do it in PHP. Flash would be one possibility. But
you also need to have a way for the exec'd job to communicate back to
the flash program - which won't be easy.

This could be easier if it weren't an exec'd program - then it would be
using the http connection. As a batch program, though, this connection
isn't available to it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 1 '07 #2
On 1 Jan 2007 11:48:57 -0800, An************@gmail.com wrote:
>I call a program through exec that can take a long time to execute.
This is fine but I would like to show some kind of animation or
something while the program is running and when it is finished letting
the user download the file.

Right now I'm using code similar to this simplified example:

----- index.php -----
<form method="post" action="genetate.php" target="_blank">
<input type="submit" value="Generate!"/>
</form>

----- generate.php -----
<?php
$tmpname = time() . md5("bla");

// Writes to $tmpname
exec("takesalotoftime $tmpname");

$len = filesize("$tmpname");

header('Content-type: application/postscript\r\n');
header("Content-Length: $len;\r\n");
header('Content-Disposition: attachment; filename="' . $tmpname
. '"\r\n');

readfile("$tmpname");
?>

So what is the best way to start the exec, show an animation until it
is finished and then send the file to the user?
One approach; show a page with an animated gif, flush the page, run the
long-running exec, then do a Javascript redirection when it's done (bearing in
mind that it's not 100% reliable).

Or move it back a step; redirect to page a with an animation and a notice to
the user to be patient, redirect to the long-running page and rely on the
browser not updating the page until the next one starts returning stuff.

If the process can provide feedback on the progress, then proc_open and
HTML_Progress from PEAR may let you get more sophisticated.

You have a few options since it looks like you're writing to a file so you can
always fetch that on a separate page - although that runs the risk of leaking
temporary files if it's not a true temp file (but if it is a true temp file
then it'd disappear anyway).

How long does it take? You may run into maximum execution time limits as well
as the users' impatience.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 1 '07 #3

Andy Hassall skrev:
On 1 Jan 2007 11:48:57 -0800, An************@gmail.com wrote:
I call a program through exec that can take a long time to execute.
This is fine but I would like to show some kind of animation or
something while the program is running and when it is finished letting
the user download the file.

Right now I'm using code similar to this simplified example:

----- index.php -----
<form method="post" action="genetate.php" target="_blank">
<input type="submit" value="Generate!"/>
</form>

----- generate.php -----
<?php
$tmpname = time() . md5("bla");

// Writes to $tmpname
exec("takesalotoftime $tmpname");

$len = filesize("$tmpname");

header('Content-type: application/postscript\r\n');
header("Content-Length: $len;\r\n");
header('Content-Disposition: attachment; filename="' . $tmpname
. '"\r\n');

readfile("$tmpname");
?>

So what is the best way to start the exec, show an animation until it
is finished and then send the file to the user?

One approach; show a page with an animated gif, flush the page, run the
long-running exec, then do a Javascript redirection when it's done (bearing in
mind that it's not 100% reliable).

Or move it back a step; redirect to page a with an animation and a notice to
the user to be patient, redirect to the long-running page and rely on the
browser not updating the page until the next one starts returning stuff.

If the process can provide feedback on the progress, then proc_open and
HTML_Progress from PEAR may let you get more sophisticated.

You have a few options since it looks like you're writing to a file so you can
always fetch that on a separate page - although that runs the risk of leaking
temporary files if it's not a true temp file (but if it is a true temp file
then it'd disappear anyway).

How long does it take? You may run into maximum execution time limits as well
as the users' impatience.
Thanks for all the suggestions but it looks like i'am not going to need
them. The execution took between 30-60 seconds on my test server, but
when I tried it on the real server it took between 1-5 seconds :)
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 2 '07 #4
On Mon, 01 Jan 2007 21:22:30 +0000, Andy Hassall wrote:
On 1 Jan 2007 11:48:57 -0800, An************@gmail.com wrote:
>>I call a program through exec that can take a long time to execute.
This is fine but I would like to show some kind of animation or
something while the program is running and when it is finished letting
the user download the file.

Right now I'm using code similar to this simplified example:

----- index.php -----
<form method="post" action="genetate.php" target="_blank">
<input type="submit" value="Generate!"/>
</form>

----- generate.php -----
<?php
$tmpname = time() . md5("bla");

// Writes to $tmpname
exec("takesalotoftime $tmpname");

$len = filesize("$tmpname");

header('Content-type: application/postscript\r\n');
header("Content-Length: $len;\r\n");
header('Content-Disposition: attachment; filename="' . $tmpname
. '"\r\n');

readfile("$tmpname");
?>

So what is the best way to start the exec, show an animation until it
is finished and then send the file to the user?

One approach; show a page with an animated gif, flush the page, run the
long-running exec, then do a Javascript redirection when it's done (bearing in
mind that it's not 100% reliable).

Or move it back a step; redirect to page a with an animation and a notice to
the user to be patient, redirect to the long-running page and rely on the
browser not updating the page until the next one starts returning stuff.

If the process can provide feedback on the progress, then proc_open and
HTML_Progress from PEAR may let you get more sophisticated.

You have a few options since it looks like you're writing to a file so you can
always fetch that on a separate page - although that runs the risk of leaking
temporary files if it's not a true temp file (but if it is a true temp file
then it'd disappear anyway).

How long does it take? You may run into maximum execution time limits as well
as the users' impatience.
In my opinion, long running things are not suitable for web interface. If
you have a batch job, you can put it on some kind of a queue and
communicate results. Having browser waiting for the data from the server
for extended periods of time is an extremely bad practice, application
design-wise. It is practically guaranteed to infuriate users and make them
demand the designer's head on an aluminum platter. No need to waste silver.

--
http://www.mladen-gogala.com
Jan 3 '07 #5

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

Similar topics

2
by: D. Alvarado | last post by:
Hello, I am running PHP 4 on Apache 1.31 for Fedora Core 2 Linux. I run a process exec("/bin/sh $my_script", $output, $return); that takes about 15-20 seconds but produces multiple lines of...
1
by: Chad | last post by:
I need my java program to exec an external .exe file, but the problem is that this program being exec()'ed prompts the user for two pieces of information. I am trying to get my java program to...
45
by: It's me | last post by:
I am new to the Python language. How do I do something like this: I know that a = 3 y = "a" print eval(y)
2
by: jzz | last post by:
I have the following HTML code, which executes a PHP script. ============================================================================= <!--HTML CODE--> <html><head><title>Vulneraility...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
1
by: Gunnar G | last post by:
If I wish to run an external application with exec(), does the execution of the PHP script halt until the external application has finished?
3
by: bwgames | last post by:
Hi there, I have a script that takes two inputs from the keyboard to change some settings on some equipment. I would usually run this as e.g. ben@srv001:/$ change-settings<enter> new-setting...
26
by: warth33 | last post by:
Hello I have a php site. Some page needs to call an external program. The programs are home made c# applications. It uses to work without problem. For a while. Maybe it work for some hour....
10
by: sophie_newbie | last post by:
Hi, I'm trying to write a piece of code that spawns a thread and prints dots every half second until the thread spawned is finished. Code is something like this: import threading class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.