Starting an indipendent php process 
Author Message
 Starting an indipendent php process

A php page call an indipendent slow function that require much seconds to be
executed. Server doesn't send any data before the complete function process
finish. The wait time to view the page is too long.
I tried flush(), putting it after the main code execution and before the
slow function start, but it still wait the function end. Same result using
exec().
I can't access to cron on web server.

I could try to start the slow function with a socket that connect to the php
file containing only the slow function. Maybe it will send me the main php
page output, and start the slow function separately.
Unfortunately I still haven't a good socket skill, but I just would like to
know if the socket idea will resolve my problem.
Very thanks in advance.

Viames



Mon, 20 Jun 2005 18:11:19 GMT  
 Starting an indipendent php process

Quote:

> A php page call an indipendent slow function that require much seconds to
> be executed. Server doesn't send any data before the complete function
> process finish. The wait time to view the page is too long.
> I tried flush(), putting it after the main code execution and before the
> slow function start, but it still wait the function end. Same result using
> exec().
> I can't access to cron on web server.

> I could try to start the slow function with a socket that connect to the
> php file containing only the slow function. Maybe it will send me the main
> php page output, and start the slow function separately.
> Unfortunately I still haven't a good socket skill, but I just would like
> to know if the socket idea will resolve my problem.
> Very thanks in advance.

> Viames

Make sure output buffering is off, make sure everything is flushed first,
if it's a function written in PHP, add some output statements to stop it
from timing out (like printing a newline every loop).  If it's in C, rewrite
it!


Mon, 20 Jun 2005 20:12:59 GMT  
 Starting an indipendent php process
I set in my php.ini "output_buffering = Off", but flush() doesn't work as I
expect. Everything come to my browser only when the slow function has
finished his work.


Mon, 20 Jun 2005 22:28:27 GMT  
 Starting an indipendent php process


Quote:
> I set in my php.ini "output_buffering = Off", but flush() doesn't work
> as I expect. Everything come to my browser only when the slow function
> has finished his work.

It shouldn't. Where are you using flush(), and are you sure it's not just
your browser that just doesn't display it? Some browsers seem to cache the
first 256 bytes of output or so before displaying anything.

KAH



Tue, 21 Jun 2005 03:24:06 GMT  
 Starting an indipendent php process

Quote:

> It shouldn't. Where are you using flush(), and are you sure it's not just
> your browser that just doesn't display it? Some browsers seem to cache the
> first 256 bytes of output or so before displaying anything.

I see, but the server process my page and send me the complete page result,
a long html code, much over 256 bytes. I get the same result from
Win/Explorer and Linux/Mozilla.
Do you know if launching external socket connection, it will starts the slow
function indipendently?


Tue, 21 Jun 2005 09:04:24 GMT  
 Starting an indipendent php process


Quote:
> I see, but the server process my page and send me the complete page
> result, a long html code, much over 256 bytes. I get the same result
> from Win/Explorer and Linux/Mozilla.
> Do you know if launching external socket connection, it will starts
> the slow function indipendently?

Show us your code, please.

KAH



Wed, 22 Jun 2005 00:17:55 GMT  
 Starting an indipendent php process
Thanks anyway, I got a solution that works fine for me:

<?php
// ... page code
// at last, the
$fs = fsockopen('www.mysite.com', 80, $errno, $errstr, 30) or die();
fputs($fs, "HEAD /mypage.php HTTP/1.0\r\n"."Host: www.mysite.com\r\n\r\n");
fclose($fs);
?>

This code just open a socket to the page mypage.php. It starts a slow
process (that is in the mypage.php) indipendently from the page where this
socket open is in, and the process doesn't affect the page speed. Of course
the process started by the socket connection can't be stopped as well :D

Viames



Thu, 07 Jul 2005 08:08:40 GMT  
 Starting an indipendent php process

Quote:
> I see, but the server process my page and send me the complete page result,
> a long html code, much over 256 bytes. I get the same result from
> Win/Explorer and Linux/Mozilla.

Chances are that the flush() is working fine, but if your code is
inside <table> tags then the browser won't render it until it gets the
</table> tag.  Otherwise it should render it as it gets it - try just
using the function, without any surrounding html.

Or telnet into port 80 of the server and see what it's actually
doing... :)

Kevin



Fri, 08 Jul 2005 09:15:27 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Apache + PHP not processing php

2. which site to start writing php?

3. starting applications with php

4. Perl script can't read cookies after PHP output starts

5. Starting a comp.lang.php FAQ?

6. php keeps starting new sessions rather than use current session

7. Value entered in form is not processed by PHP script

8. Processing defines in PHP

9. Can php create a daemon process?

10. php not processing

11. VW 3.0 fails starting NT-Process

12. Starting a VW process from the OS

 

 
Powered by phpBB® Forum Software