开发者

PHP + shell - Start a process from PHP

Good day to all.

I need to do this:

From a computer somewhere in this world I need to access a specific URL and start a process. The only problem is that since the process may last over 5 hours and may return some errors (the process will move over them) PHP commands like exec, shell_exec, etc don't work (don't exactly know why but... all return error and stop execution)... so I tried this:

  • I made a cron that runs a script
  • use php to write the script file

Everything works fine but I need to return a counter telling me when the process will start so, when I run the php script that edit the shell script I return the hour of the system and start counting till the next full minute (when the script will be executed).

Now the only problem is this:

The counter SEEMS to work ok... but also the process needs some time to start and that time may vary from 3-4 sec to 1 minute. My question is... can I get sometime of hint at least if not the exact time of when the process will start up and the exact time when it did start?

I dunno... like writing in a file and a php script read it for a minute to see when something changed?

Ok... I promised I'll add some details:

The process is streaming. Live. So this is what I need to do:

create a stream give a counter to the user when the stream will start

I use ffmpeg for streaming. The start.php have something like:

开发者_如何学Go
   // Create a file called script.sh

   $string = "ffserver & ffmpeg -i pipe.avi http://localhost:8090/feed1.ffm& echo exit 0 > script.sh& exit 0";

   //write string to script.sh
   //create a file that contains the exact time when the script was run.

The cron looks like this:

   * * * * * /var/www/html/script.sh > /dev/null
   and some other crons that doesn't matter

So I can create a counter that gets the time when the script was run and count till the next minute when the cron will run. The thing is that ffmpeg has some time until it starts (testing codecs, checking file etc.) I need to get that time and include it in timer so when the stream starts the guy that speaks says "Hello". Is not nice for him to do something like "Ok... is this working? Yes? Hello ppl." and is not good for the users to loose the first 3-4 sentences. That's why I need the moment when ffmpeg starts and somehow pass it to a php script. I can manage from there.


I have worked at places where crontab was only cycled every 5 mins, but more recently crontab seem to be cycled every 1 minute. It is probably a configurable value, so if you don't think your crontab is starting until some multiple of minutes that may be the reason.

Your process should start after the time seconds value moves from 59 to 00. There may also be minor delays starting the crontab entry if some other process is already using most/all of systems resources.

But looking at this from another point of view, if you are creating crontab entries with a specific time value, then you know what time to start looking at, + 2-3 seconds, right?

Please modify your posting to include a sample of what your crontab entry that your system creates looks like (are there any '*' in it, being my main interest).


Rereading your post, I see you're not programamtically creating the crontab entry. Nevermind on that.

If your process is running for many hours, why you need to immediately attach to it. If it crashes in the first 30 seconds, isn't waiting 1 minute max to find that out good enough?

Finally, in the shell environment, there is 99.99999% of the time, a way to capture a process's output from the very beginning. The idea of having to wait, to start getting the output requires more explanation. Is this something todo with that the program is running on a remote machine? The remote program should capture it's output, and then you 'get' that output as a seperate sub/co-process.

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜