FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Queuing at job from within php program?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Queuing at job from within php program? [message #175675 is a reply to message #175666] Tue, 18 October 2011 03:43 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Mon, 17 Oct 2011 13:24:27 +0000, bobm3 wrote:

> Fellow php'ers;
>
> I'm having some difficulty getting this to work: Based on a date/time
> selected by a user on a web form I would like to use the "at" command to
> schedule that task.
>
> I've tried various php functions (system, exec, passthru) with the same
> results (return code 1 - which I cannot seem to get the error message
> from).
>
> Here is a sample code snippet:
>
> $cmd = "echo \"podcast -c $filename\" | at $hr:$mn $_ampm";
> passthru("$cmd", $Retcode);
> echo "$Retcode";
>
> returns 1
>
> Then I thought that perhaps the 'at' was not reading stdin in this case
> so I tried a temporary file approach:
>
> $cmd = "echo \"podcast -c $filename\""; file_put_contents
($filename.tmp,
> $cmd); passthru("at $_hr:$_mn $_ampm < $filename.tmp", $_RetVal); echo
> "$_RetVal";
>
> This time it returned 2
>
> I've got to be misunderstanding this function. So, I thought if any of
> you skilled readers have had luck with doing something like this you may
> be willing to share. However, any other suggestions greatly
> appreciated.
>
> Thanks

Here's an example of calling a php file every minute to queue itself to
run again a minute later. Note that it uses a script file and a php file

Note that I've used "/path/" to indicate that on my system I used
absolute paths to define both files.

The script file calls the php file with the php cli processor:

--8<-- start /path/testit --8<--
#!/bin/bash
php /path/testit.php
--8<-- end /path/testit --8<--

and the php file executes a system call to schedule the script file:

--8<-- start /path/testit.php --8<--
<?php
system("at -m now +1 minutes -f /path/testit");
?>
--8<-- end /path/testit.php --8<--

I did notice that in my /etc/at.deny is an entry for my web server
process, so I guess that any attempt to invoke at from within the web
server would fail. I don't recall setting this, so it may be a default -
might be worth checking?

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: declaring private variable in class
Next Topic: simple session question
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 19 16:51:59 GMT 2024

Total time taken to generate the page: 0.04743 seconds