php-general Digest 4 Nov 2008 13:24:13 -0000 Issue 5772

Topics (messages 282828 through 282842):

wget --spider and ignore_user_abort(TRUE)
        282828 by: Martino Dell'Ambrogio
        282830 by: Richard Heyes
        282832 by: Martino Dell'Ambrogio
        282833 by: Richard Heyes
        282834 by: Martino Dell'Ambrogio
        282835 by: Richard Heyes
        282837 by: Martino Dell'Ambrogio
        282838 by: Jochem Maas
        282839 by: Richard Heyes
        282840 by: Martino Dell'Ambrogio

Re: Mailing lists
        282829 by: Richard Heyes

Re: Sending mail with Outlook high priority
        282831 by: Richard Heyes

Re: Time zones and $_ENV vs getenv
        282836 by: John Coppens

Re: Yahoo/Gmail/Hotmail Contacts API
        282841 by: Feris

Re: COM and VARIANT types
        282842 by: Alex Bovey

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hi there,

I am trying to get a script to run in background no matter what, but I am 
obviously doing it wrong.

Here is the entire code:

<?php
//first instruction to be sure it is parsed
ignore_user_abort(TRUE);
set_time_limit(3600);

//sleep(10);

//this will send the HTTP code + headers + test
ob_start();
echo "test";
ob_flush();

sleep(10);
system("touch /tmp/aborting");
?>

The file /tmp/aborting get touched if I abort the connection in a 
browser, or if I run "wget blabla/script.php" and kill wget... in fact it 
works perfectly in any way, but it doesn't work when I use the "--spider" 
option of wget.

That option does a HEAD request and as soon as it receives the HTTP code 
200 closes the connection. The script is then aborted and the file
/tmp/aborting never get touched.

I initially thought that ignore_user_abort() never get to be parsed 
because the connection is closed before and I set it in the php.ini file, 
but that didn't work.
I then realized that PHP has to get at least to the ob_flush() call, 
that's proved by putting a sleep(10) just before the ob_start() call: 
wget --spider waits 10 seconds before exiting.

Why is ignore_user_abort(TRUE) ignored, what am I missing?
I probably shouldn't say that while asking for help, but... is this a bug?

I am using PHP 5.2.6-pl7-gentoo via Apache 2.2.9-r1 (Gentoo) with 
"worker" MPM.

Thank you for your help,
tillo

--- End Message ---
--- Begin Message ---
> I am trying to get a script to run in background no matter what, but I am
> obviously doing it wrong.

1. Have it executed via a shell command.
2. Redirect all output.
3. Append the ampersand.

eg. A commandx such as:

sleep 5  >/dev/null 2>&1 &

would become:

<?php
     exec('sleep 5 > /dev/null 2>&1 &');
?>

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
On Tue, 04 Nov 2008 10:03:11 +0000, Richard Heyes wrote:

>> I am trying to get a script to run in background no matter what, but I
>> am obviously doing it wrong.
> 
> 1. Have it executed via a shell command. 2. Redirect all output.
> 3. Append the ampersand.

This is not what I need, but thanks.

The code snippet I wrote is just an example of the PHP connection 
handling going wrong (or not as I want to).
The real script doesn't sleep and does much more then executing a system 
command.

The question here is: why a PHP script called via 'wget --spider' through 
Apache/2 gets killed as soon as the HTTP reply code is sent, even if 
ignore_user_abort() is set?

--- End Message ---
--- Begin Message ---
> The question here is: why a PHP script called via 'wget --spider' through
> Apache/2 gets killed as soon as the HTTP reply code is sent, even if
> ignore_user_abort() is set?

A script ending naturally is not the same as a user aborting.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
On Tue, 04 Nov 2008 11:37:15 +0000, Richard Heyes wrote:

>> The question here is: why a PHP script called via 'wget --spider'
>> through Apache/2 gets killed as soon as the HTTP reply code is sent,
>> even if ignore_user_abort() is set?
> 
> A script ending naturally is not the same as a user aborting.

I agree, but why is the script ending? Does PHP is set to stop running as 
soon as it knows the size of the reply, required by an HEAD request? How 
can I override this?

(by "script" I mean the PHP script. Your previous post forks PHP and runs 
a system command without exiting it when the script exits ("nohup" should 
be used instead of the output redirection), I understood that but it is 
not what I need; I need the PHP script to keep running until the end)

--- End Message ---
--- Begin Message ---
> I need the PHP script to keep running until the end)

Until the end of what? Time? If you want your HTTP request to finish
and a script to continue regardless then use the method I suggested,
an start a shell process going.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
On Tue, 04 Nov 2008 11:59:20 +0000, Richard Heyes wrote:

>> I need the PHP script to keep running until the end)
> 
> Until the end of what? Time?
Until the end of the script.

> If you want your HTTP request to finish and
> a script to continue regardless then use the method I suggested, an
> start a shell process going.

I insist :) sorry. You didn't understand what I am doing, probably 
because of my ESL...

- I have a PHP script

- this PHP script has X sequential functions

- every function must be executed

- if I open the page (GET request), all is fine

- if I open the page then stop the client connection while the script is 
still running, all is fine (client sends an RST, ignore_user_abort kicks 
in, script goes through all of its X functions then exits at the end of 
the script)

- if I use wget --spider (HEAD request) the script exits just after the 
first output, all the functions below never get executed

This has nothing to do with any system command.

Is it clear now?

--- End Message ---
--- Begin Message ---
Martino Dell'Ambrogio schreef:
> On Tue, 04 Nov 2008 11:59:20 +0000, Richard Heyes wrote:
> 
>>> I need the PHP script to keep running until the end)
>> Until the end of what? Time?
> Until the end of the script.
> 
>> If you want your HTTP request to finish and
>> a script to continue regardless then use the method I suggested, an
>> start a shell process going.
> 
> I insist :) sorry. You didn't understand what I am doing, probably 
> because of my ESL...
> 
> - I have a PHP script
> 
> - this PHP script has X sequential functions
> 
> - every function must be executed
> 
> - if I open the page (GET request), all is fine
> 
> - if I open the page then stop the client connection while the script is 
> still running, all is fine (client sends an RST, ignore_user_abort kicks 
> in, script goes through all of its X functions then exits at the end of 
> the script)
> 
> - if I use wget --spider (HEAD request) the script exits just after the 
> first output, all the functions below never get executed

try testing for the request type (i.e. HEAD) and if found don't output
anything at all.

seems like apache (not the user) is shutting down the request as soon
as it recieves the first byte of the request body.

> 
> This has nothing to do with any system command.
> 
> Is it clear now?
> 


--- End Message ---
--- Begin Message ---
> - if I use wget --spider (HEAD request) the script exits just after the
> first output, all the functions below never get executed
>
> This has nothing to do with any system command.

Then have your HTTP request trigger a system command that runs on
regardless. The HTTP request continues on after triggering the system
command, not giving a "tiny rats ass" what it does. You can use the
exec() code I gave you to do this (ie using an ampersand and
redirecting the output streams).

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
On Tue, 04 Nov 2008 13:24:41 +0100, Jochem Maas wrote:

> try testing for the request type (i.e. HEAD) and if found don't output
> anything at all.

This is a nice workaround and works perfectly, thanks!

> seems like apache (not the user) is shutting down the request as soon as
> it recieves the first byte of the request body.

I thought so, I just hoped there was some way to make PHP (or Apache) 
continue the work in any case. The no-output way works for me, thank you.

tillo

--- End Message ---
--- Begin Message ---
>    Which is why it's always best to remember one thing, especially in
> programming: never underestimate the power of stupidity.

Or ignorance. Even in the face of something that's blindingly obvious.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
> Is there any PHP functionality for sending mail and attaching a high
> priority to the mail item ?

My htmlMimeMail code will do this for and, make it much easier too.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

--- End Message ---
--- Begin Message ---
On Mon, 3 Nov 2008 13:01:14 -0200
[EMAIL PROTECTED] (John Coppens) wrote:

> I'm confused... Can someone point me to some more tests I could do?

Solved.

Apparently the apachectl start/stop/restart script didn't work correctly,
or wasn't able to do its work. I _thought_ I had restart apache after
each modification, but it just continued running.

John

--- End Message ---
--- Begin Message ---
Hi Everyone,
Thanks for all the recommendation. Will explore them all.

Regards,

Feris

On Sun, Nov 2, 2008 at 7:52 PM, Eric Butera <[EMAIL PROTECTED]> wrote:

> On Sun, Nov 2, 2008 at 5:03 AM, Richard Heyes <[EMAIL PROTECTED]> wrote:
> >> Open id's really a toy at this point.
> >
> > Now that MS and Google have signed up it will soon get a lot bigger.
> >
> > http://news.bbc.co.uk/1/hi/technology/7699320.stm
> >
> > --
> > Richard Heyes
> >
> > HTML5 Graphing for FF, Chrome, Opera and Safari:
> > http://www.rgraph.org (Updated October 25th)
> >
>
> When we see the ability to log into said services with openid, you'll
> have an argument.  AOL has been a provider for years, nothing has
> changed.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> I think this may be what you are looking for, but I don't know how
> much it helps:
>
> http://www.marin.clara.net/COM/variant_type_definitions.htm
>
> Andrew

Thanks Andrew - it's a start!

Alex

-- 
Alex Bovey
Web Developer | Alex Bovey Consultancy Ltd
Registered in England & Wales no. 6471391 | VAT no. 934 8959 65
PHP | MySQL | AJAX | XHTML | CSS | Javascript | XML | W3C Accessibility

--- End Message ---

Reply via email to