phpbar.de logo

Mailinglisten-Archive

[php] mit php prozess im BG starten

[php] mit php prozess im BG starten

Cyrill Schumacher php_(at)_phpcenter.de
Thu, 10 Jan 2002 16:09:50 +0100


> Das Programm prog.exe soll aus dem Script gestartet werden und PHP soll
> nicht warten,
> bis das Programm beendet ist (was in meinem Fall SEHR lange dauern
> kann), sondern
> gleich weitermachen.

versuch mit "mikehub"

Webpage: http://www.naken.cc/mikehup.php


INTRODUCTION

This is mikehup (errr.. my rewritten version.. the original
was lost by my ISP that didn't backup my web page.  bastads :)

Anyway, this program solves the problem that PHP cannot execute
a program in the background.  Actually, PHP CAN execute a program
in the background if the program being called closes stdin, stdout,
and stderr.  For example, if you had a web page that would play
an mp3 on your local computer, the PHP code would have something
like this in it:

system("mpg123 yngwie.mp3 &");

Unfortunately the & will not let mpg123 run as a background process
because mpg123 keeps stdin, stdout, and stderr open.  Therefore,
the page will not finish loading until the mp3 is done playing.

Since most people don't want to play with the source code for mpg123
and a lot of programs don't give you the source code at all, I created
mikehup.  When you call a program with mikehup, it will close stdin,
stdout, and stderr before executing your program letting.  This allows
your program to run in the background and your web page will load
immediately without waiting for it to finish.  The new PHP page would
look like this:

system("/usr/local/bin/mikehup mpg123 yngwie.mp3 &");

REMEMBER to check paths to files (you may need /usr/local/bin/mpg123
to make it run) and don't forget the & at the end of the line.


php::bar PHP Wiki   -   Listenarchive