Flash calling Php calling Perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a flash program that posts user enter data to a php program on
the server.
The php program then saves this data in a database and then uses system
() to call the perl program which takes the data and generates a pdf
file and thumbnail images.
The php program, on completion of the perl program then sends a status
back to flash telling it was done. Flash then calls the php script to
get thes thumbnails for the view to see. This process can take 10 or
more seconds on the perl side to complete.

We are changing the flash aplication so that there is no need for it
to display the thumbnails after posting the data over and I am looking
for a way of having the php program just start the perl program but
not wait for it to complete before sending back the status to flash.

From all the possible PHP commands, exec(), shell_exec(), passthru()
and system(), it seems that they all wait for the called program to
finish, is there a way to just start the program and not wait for it
to complete?

The other method would be to send the results back to flash prior to
calling the perl program and not care how long perl took to do its
job. Would flush() and ob_flush() be sufficient to force this
information out to flash (the only information being sent back is
"result=saved" or "result=fail")?

If this is not possible, then on the perl side (crossposted to
comp.lang.perl.misc for this question), is there a way of having a
script take the command line arguments passed by php's shell() and
forking (is this right term?) the real perl program and ending so that
php is not waiting for the real program to finish?

Bill H

Re: Flash calling Php calling Perl

Bill H wrote:
Quoted text here. Click to load it


Lots of hits show how you run programs in the background from PHP.  How
to do it is system specific, though, and you must redirect stdout.

For instance in Linux, you might do

exec("/usr/bin/perl /home/mydir/perlscript > /dev/null &");

Quoted text here. Click to load it

Not reliably.  flush() and ob_flush() clear the PHP buffers, but you
can't force the data to be sent from the web server.  The only way to
ensure the data is sent is for the script to end.

Quoted text here. Click to load it

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Flash calling Php calling Perl

Quoted text here. Click to load it

Why are you using PHP if all PHP does is act as an intermediary to
accept input from Flash and emit output to Perl? Do you really need to
have insert and select queries from a database? Seems to me you would
have a cleaner and more stable app calling Perl directly and by-
passing PHP and the DB entirely to the extent that you perform a write
and read operation before you start creating your files.

insert_data($connection_dbh, $user_supplied_data);

Quoted text here. Click to load it

You implied that this would be suitable for a multi-threaded app but
didn't directly say so. If you have multiple cores and multiple tasks,
you might be able to decompose your tasks into different processes and
queue them to pass to any processor that can run the process. If you
have only one processor this probably wouldn't make much sense.

Quoted text here. Click to load it

I have a couple of tasks that process several thousand files at a time
using data queried from a database, creating, printing, emailing, and
then deleting each file. My main Perl script calls helper scripts each
of which is designed to do exactly one thing. It's mostly a hack, but
it works (which is the main thing) and I don't have to wait until the
last file is handled to start using the earlier files.


Re: Flash calling Php calling Perl

Quoted text here. Click to load it

If it was me, unless your perl script is doing something really
special I'd do it all in php:

http://www.fpdf.org /

Re: Flash calling Php calling Perl

[f'ups set to c.l.perl.misc]

Quoted text here. Click to load it

The simplest way of doing this (assuming a Unix system, or some other
system with a real fork(2)) would be to have

    fork and exit;

as the first 'real' statement in your Perl program. You would probably
want to add error checking, of course. See perldoc perlipc.


Site Timeline