Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3443 > unrolled thread

Queuing at job from within php program?

Started bybobm3@worthless.info
First post2011-10-17 13:24 +0000
Last post2011-10-20 21:21 -0400
Articles 11 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  Queuing at job from within php program? bobm3@worthless.info - 2011-10-17 13:24 +0000
    Re: Queuing at job from within php program? Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-17 11:20 -0400
      Re: Queuing at job from within php program? bobm3@worthless.info - 2011-10-17 15:51 +0000
        Re: Queuing at job from within php program? Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-17 12:47 -0400
          Re: Queuing at job from within php program? Robert Heller <heller@deepsoft.com> - 2011-10-17 13:27 -0500
            Re: Queuing at job from within php program? Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-17 16:53 -0400
        Re: Queuing at job from within php program? "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-10-18 09:51 +0200
    Re: Queuing at job from within php program? Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-18 03:43 +0000
    Re: Queuing at job from within php program? Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-10-18 10:12 +0200
      Re: Queuing at job from within php program? bobm3@worthless.info - 2011-10-19 21:40 -0400
        Re: Queuing at job from within php program? SOLVED! bobm3@worthless.info - 2011-10-20 21:21 -0400

#3443 — Queuing at job from within php program?

Frombobm3@worthless.info
Date2011-10-17 13:24 +0000
SubjectQueuing at job from within php program?
Message-ID<j7haab$mh2$1@dont-email.me>
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

[toc] | [next] | [standalone]


#3444

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-17 11:20 -0400
Message-ID<j7hh49$dko$1@dont-email.me>
In reply to#3443
On 10/17/2011 9:24 AM, bobm3@worthless.info 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


What is actually in $cmd when you execute the passthru command?

What happens when you type this exact output at a command line prompt?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3445

Frombobm3@worthless.info
Date2011-10-17 15:51 +0000
Message-ID<j7hit4$ore$1@dont-email.me>
In reply to#3444
On Mon, 17 Oct 2011 11:20:38 -0400, Jerry Stuckle wrote:

> On 10/17/2011 9:24 AM, bobm3@worthless.info 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
> 
> 
> What is actually in $cmd when you execute the passthru command?
> 
> What happens when you type this exact output at a command line prompt?

I've echoed out the contents of $cmd in my testing.  It does contain 
exactly what is intended:
echo "podcast -c abc123 | at 10:01 am"

Also, the command I'm trying to execute works perfectly from the CLI with 
the same (appropriate) values.  

I'm thinking that there might be a permissions issue but I'm unable to 
obtain the error message from the passthru command.  

I suppose next I will try to create a small php script to emulate this 
from the CLI and perhaps them I will see the error (if any).

Thanks

[toc] | [prev] | [next] | [standalone]


#3446

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-17 12:47 -0400
Message-ID<j7hm6f$ish$1@dont-email.me>
In reply to#3445
On 10/17/2011 11:51 AM, bobm3@worthless.info wrote:
> On Mon, 17 Oct 2011 11:20:38 -0400, Jerry Stuckle wrote:
>
>> On 10/17/2011 9:24 AM, bobm3@worthless.info 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
>>
>>
>> What is actually in $cmd when you execute the passthru command?
>>
>> What happens when you type this exact output at a command line prompt?
>
> I've echoed out the contents of $cmd in my testing.  It does contain
> exactly what is intended:
> echo "podcast -c abc123 | at 10:01 am"
>
> Also, the command I'm trying to execute works perfectly from the CLI with
> the same (appropriate) values.
>
> I'm thinking that there might be a permissions issue but I'm unable to
> obtain the error message from the passthru command.
>
> I suppose next I will try to create a small php script to emulate this
> from the CLI and perhaps them I will see the error (if any).
>
> Thanks

OK, when you enter that exactly from the CLI it works?  Are you 
executing it as root or another user?

Next: the home directory for the web server will be different than the 
one from the CLI.  Also, the web server will have different permissions. 
  Usually the web server user will not have permission to access the 
atjobs directory (/var/spool/cron/atjobs on Debian).

Try su'ing (or sudo'ing) to the web server's id, change to the web 
server's root directory and execute the command.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3447

FromRobert Heller <heller@deepsoft.com>
Date2011-10-17 13:27 -0500
Message-ID<y_KdnboKrJ7m7gHTnZ2dnUVZ_sadnZ2d@posted.localnet>
In reply to#3446
At Mon, 17 Oct 2011 12:47:08 -0400 Jerry Stuckle <jstucklex@attglobal.net> wrote:

> 
> On 10/17/2011 11:51 AM, bobm3@worthless.info wrote:
> > On Mon, 17 Oct 2011 11:20:38 -0400, Jerry Stuckle wrote:
> >
> >> On 10/17/2011 9:24 AM, bobm3@worthless.info 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
> >>
> >>
> >> What is actually in $cmd when you execute the passthru command?
> >>
> >> What happens when you type this exact output at a command line prompt?
> >
> > I've echoed out the contents of $cmd in my testing.  It does contain
> > exactly what is intended:
> > echo "podcast -c abc123 | at 10:01 am"
> >
> > Also, the command I'm trying to execute works perfectly from the CLI with
> > the same (appropriate) values.
> >
> > I'm thinking that there might be a permissions issue but I'm unable to
> > obtain the error message from the passthru command.
> >
> > I suppose next I will try to create a small php script to emulate this
> > from the CLI and perhaps them I will see the error (if any).
> >
> > Thanks
> 
> OK, when you enter that exactly from the CLI it works?  Are you 
> executing it as root or another user?
> 
> Next: the home directory for the web server will be different than the 
> one from the CLI.  Also, the web server will have different permissions. 
>   Usually the web server user will not have permission to access the 
> atjobs directory (/var/spool/cron/atjobs on Debian).
> 
> Try su'ing (or sudo'ing) to the web server's id, change to the web 
> server's root directory and execute the command.

On a *typical* (eg properly secured) LAMP server, the web server would
be running as the user 'apache' and the apache user's shell will be set
to '/sbin/nologin'.  This means that the web server user cannot login to
a shell.  This implies that you cannot fork() a *shell*:

sauron.deepsoft.com% sudo su apache -l
This account is currently not available.

In order to run an at command, you need to fork() a shell process.


-- 
Robert Heller             -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


              

[toc] | [prev] | [next] | [standalone]


#3450

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-17 16:53 -0400
Message-ID<j7i4l4$tch$1@dont-email.me>
In reply to#3447
On 10/17/2011 2:27 PM, Robert Heller wrote:
> At Mon, 17 Oct 2011 12:47:08 -0400 Jerry Stuckle<jstucklex@attglobal.net>  wrote:
>
>>
>> On 10/17/2011 11:51 AM, bobm3@worthless.info wrote:
>>> On Mon, 17 Oct 2011 11:20:38 -0400, Jerry Stuckle wrote:
>>>
>>>> On 10/17/2011 9:24 AM, bobm3@worthless.info 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
>>>>
>>>>
>>>> What is actually in $cmd when you execute the passthru command?
>>>>
>>>> What happens when you type this exact output at a command line prompt?
>>>
>>> I've echoed out the contents of $cmd in my testing.  It does contain
>>> exactly what is intended:
>>> echo "podcast -c abc123 | at 10:01 am"
>>>
>>> Also, the command I'm trying to execute works perfectly from the CLI with
>>> the same (appropriate) values.
>>>
>>> I'm thinking that there might be a permissions issue but I'm unable to
>>> obtain the error message from the passthru command.
>>>
>>> I suppose next I will try to create a small php script to emulate this
>>> from the CLI and perhaps them I will see the error (if any).
>>>
>>> Thanks
>>
>> OK, when you enter that exactly from the CLI it works?  Are you
>> executing it as root or another user?
>>
>> Next: the home directory for the web server will be different than the
>> one from the CLI.  Also, the web server will have different permissions.
>>    Usually the web server user will not have permission to access the
>> atjobs directory (/var/spool/cron/atjobs on Debian).
>>
>> Try su'ing (or sudo'ing) to the web server's id, change to the web
>> server's root directory and execute the command.
>
> On a *typical* (eg properly secured) LAMP server, the web server would
> be running as the user 'apache' and the apache user's shell will be set
> to '/sbin/nologin'.  This means that the web server user cannot login to
> a shell.  This implies that you cannot fork() a *shell*:
>
> sauron.deepsoft.com% sudo su apache -l
> This account is currently not available.
>
> In order to run an at command, you need to fork() a shell process.
>
>

It depends on what you're doing.  Many web servers allow you to fork a 
command, for good reasons.  Just because you can execute a command shell 
doesn't mean it's not properly secured.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3455

From"Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Date2011-10-18 09:51 +0200
Message-ID<j7jb5s$g2i$1@dont-email.me>
In reply to#3445
El 17/10/2011 17:51, bobm3@worthless.info escribió/wrote:
>> What is actually in $cmd when you execute the passthru command?
>>
>> What happens when you type this exact output at a command line prompt?
>
> I've echoed out the contents of $cmd in my testing.  It does contain
> exactly what is intended:
> echo "podcast -c abc123 | at 10:01 am"

This is the echo command. All it does is printing a string into the 
standard output. PHP doesn't actually do much with your command; it 
basically feeds the shell with it as-is. So before caring about 
executing a command from PHP, you need to make sure that the command 
itself works as expected.


-- 
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

[toc] | [prev] | [next] | [standalone]


#3452

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-10-18 03:43 +0000
Message-ID<4e9cf5f5$0$28566$a8266bb1@newsreader.readnews.com>
In reply to#3443
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

[toc] | [prev] | [next] | [standalone]


#3456

FromErwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
Date2011-10-18 10:12 +0200
Message-ID<4e9d34dc$0$6917$e4fe514c@news2.news.xs4all.nl>
In reply to#3443
On 10/17/2011 3:24 PM, bobm3@worthless.info 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).
>

<snip>

Others commented on the issues that can arrise with rights.
(More specific: the PHP-user (www-data or apache) adding tasks.)

I want to add another approach that I prefer.
(Written for Unix-lie systems. Replace cronjob with task-scheduler for 
Windows.)

Personally I don't like my software to schedule new tasks automatically.
So if I need scheduling, I prefer to create 1 cronjob by hand, for 
www-data, that runs a script (can be PHP).
That script than pulls from a database certain tasks WHEN they are needed.
Depending on the time-resolution you need you can run this cron-job once 
a day, once an hour, every minute, etc.

I like it that way because I can catch the result, log the last time it 
ran, etc. And e-mail myself or some admin in case of failure.

Just a thought. Maybe it helps in your situation.
If not, consider this noise. ;-)

Regards,
Erwin Moller


-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#3467

Frombobm3@worthless.info
Date2011-10-19 21:40 -0400
Message-ID<vsuu975q1upvd1ac7n0rha9fdkk90trdl7@4ax.com>
In reply to#3456
On Tue, 18 Oct 2011 10:12:13 +0200, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> wrote:

>On 10/17/2011 3:24 PM, bobm3@worthless.info 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).
>>
>
><snip>
>
>Others commented on the issues that can arrise with rights.
>(More specific: the PHP-user (www-data or apache) adding tasks.)
>
>I want to add another approach that I prefer.
>(Written for Unix-lie systems. Replace cronjob with task-scheduler for 
>Windows.)
>
>Personally I don't like my software to schedule new tasks automatically.
>So if I need scheduling, I prefer to create 1 cronjob by hand, for 
>www-data, that runs a script (can be PHP).
>That script than pulls from a database certain tasks WHEN they are needed.
>Depending on the time-resolution you need you can run this cron-job once 
>a day, once an hour, every minute, etc.
>
>I like it that way because I can catch the result, log the last time it 
>ran, etc. And e-mail myself or some admin in case of failure.
>
>Just a thought. Maybe it helps in your situation.
>If not, consider this noise. ;-)
>
>Regards,
>Erwin Moller

Thanks all for the great comments.  I haven't looked at the at.deny
file yet but I will.   Regarding the suggestion about storing the
request and triggering at defined intervals:  that's my direction. But
seeing how I'm replacing a manual system now I need something to queue
these requests short-term while I find time to complete the back end.

Thanks again - Bob

[toc] | [prev] | [next] | [standalone]


#3473 — Re: Queuing at job from within php program? SOLVED!

Frombobm3@worthless.info
Date2011-10-20 21:21 -0400
SubjectRe: Queuing at job from within php program? SOLVED!
Message-ID<g6i1a7h6qvjtfjcu0s8mqpd9qgoqn9lf5a@4ax.com>
In reply to#3467
It was in fact an entry in the at.deny file.  I've temporarily
circumvented this until I have a better solution.  Thanks all.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web