0

I'm participating in a development of a php program and we are trying to improve its performance in stuff like:

Execute, finish output to the user, do scheduled stuff.

The objective here is to send information to apache, IIS, etc... Stating that the information about all is done can be sent to the browser. Because the way things work in this program, it's supposed not to cache all output, measure it and then output, it's supposed to output information as it is being processed, as soon as possible, so ob_* functions is not exactly an option.

How can I accomplish that? I can only find an option for this when using output buffering...

Note: curl is also not an option. Some servers in which this is supposed to work have it disabled. Same for the other common stuff, shell_exec(), exec(), etc...

brunoais
  • 6,258
  • 8
  • 39
  • 59
  • 1
    I really don't understand what you're trying to do here. – netcoder Mar 20 '12 at 20:18
  • doest [that][1] help you? [1]: http://stackoverflow.com/questions/5339393/how-to-finish-http-response-and-do-further-process-in-php – maosmurf Mar 20 '12 at 20:18
  • @user671373 not really... I only found something that works but the platform must be linux, so... not an option. – brunoais Mar 20 '12 at 20:34
  • This might help http://stackoverflow.com/questions/4806637/continue-processing-after-closing-connection – Mike B Mar 20 '12 at 20:50

1 Answers1

0

You do want to use the ob_ functions.

<?php

set_time_limit(300); 

ob_start();

echo "Starting task 1...";
long_task_1();
echo "Task 1 complete".    
ob_flush();
flush();


echo "Starting task 2...";
long_task_2();
echo "Task 2 complete".    
ob_flush();
flush();


echo "Starting task 3...";
long_task_3();
echo "Task 3 complete".    
ob_flush();
flush();

?>

Reference.

AndrewR
  • 6,668
  • 1
  • 24
  • 38
  • How does that solve my problem? How can I execute work after all the output I wanted to output is done without having a user waiting for the page to finish loading with all of it already loaded? – brunoais Mar 20 '12 at 20:37
  • This is just an example... I'll update the answer to something that would fit closer to your use case. – AndrewR Mar 20 '12 at 20:39
  • Still does not answer. I want to send all the info, say to the browser that the page is done, execute code and exit. Usually, the browser only receives that info telling that the page has ended after the script stops. I wanted to send to the browser that all is done and then continue doing other stuff – brunoais Mar 20 '12 at 21:55
  • OK, I don't think I understand your question. You want the page to complete, process data in the background, and still send updated to the completed page? If that's what you are trying to do, you could set up some kind of service or cron job to do the work, and your web page could do ajax calls to see if it is completed yet and update the page accordingly. – AndrewR Mar 21 '12 at 16:07