PHP Classes
elePHPant
Icontem

No Timeout: Split the execution of long tasks in small steps

Recommend this page to a friend!
  Info   View files View files (21)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2006-10-24 (10 years ago) RSS 2.0 feedStarStarStarStar 76%Total: 5,646 This week: 3All time: 401 This week: 377Up
Version License Categories
obuffer 1.0.0Free for non-comm...PHP 5, Utilities and Tools, AJAX
Description Author

This package can be used to split the execution of long tasks in small steps implemented by requests short enough to not exceed the PHP script execution timeout.

It uses AJAX requests to invoke each execution step. The response of the execution of each step is used to update a section of the page where the progress feedback is displayed.

The class can execute steps of several types built-in actions like database queries, search for a pattern in a file and retrieve a file blocks or lines.

Innovation Award
PHP Programming Innovation award nominee
October 2006
Number 5


Prize: One subscription to the PDF edition of the magazine by PHP Architect
Some PHP applications need to perform actions that take a long time to execute. However, in many PHP environments it is not possible to execute tasks that exceed 30 seconds, which the PHP default script execution limit.

This package provides a work around to that limit. It provides means to split long tasks in many small steps, each one should not exceed the PHP script execution limit.

It uses AJAX to automatically send requests to the Web server to execute each task step and give progress feedback on the browser, until the whole task is done.

Manuel Lemos
Picture of Johan Barbier
Name: Johan Barbier <contact>
Classes: 17 packages by
Country: France France
Innovation award
Innovation award
Nominee: 6x

Details
noTimeOut package
@author : Johan Barbier <johan.barbier@gmail.com>
@Version : 2006/10/09

Needed : PHP 5, short_open_tags to Off

DESCRIPTION:

This package is meant to retrieve a huge amount of data, or process a big php script, and not being annoyed by PHP time limit
(ie : set_time_limit, and max_execution_time).
Sometimes, you do not want, or can, modify this timeout. But it can be pretty annoying if you have a big file to read, or a huge query to process.
Well, this package can help you!

Basically, it uses xmlhttp requests to ask the server to process a part of the main process.
For exemple, for a file, it will read lines 0 to 10, then 11 to 20, and so on.
That way, you will never hit PHP time limit, but your 50000 lines file will be read and displayed anyway.
The file (or query results, or whatever) will be flushed step by step.
Just have a look at the indexX.php exemple pages. 
In most of them, PHP time limit has been set to 2s.

Addition from the 20th of October 2006 : now, stacks are supported. You can declare several stacks and have them work asynchronously.

The package consists of 2 classes:
class/class.noTimeOut.js
=> used to initialize the xmlhttp object and the required methods.
noTimeOut::initialize() method shows the properties that can/must be set
NOTA : the ARGS property is an array. It can be used to send other variables to the PHP script (useful for the new oneShot method : a basic Ajax one shot request)
noTimeOut::getData() method shows you the types of processes that can be used.
Basically :
- instanciate your object :
var oBuffer = new noTimeOut ();
- declare a stack :
oBuffer.declareStack (Stack_Name);
- initialize your properties :
oBuffer.initialize (Stack_Name, Prop_Name, Prop_Value);
- start it!
oBuffer.startWork (Stack_Name);

class/class.noTimeOut.php
=> used to process the scripts.
noTimeOut::aProps shows all the properties that can/must be initialized (it depends on the type of process chosen).
noTimeOut::aTypes shows the possible types of process (up to now)
noTimeOut::aDbServers shows the sql servers supported up to now, in a DB type of process
noTimeOut::flushMe () is the method used to flush the process
In the scripts/ folder, you will find the scripts using this class.
Basically : initialize your properties, and use flushMe() to process.


Have a look at the indexX.php exemple pages to see how to use the classes, and the different types of processes.
If you want to use the index2.php you first have to create a 'tests' database, and use the test.sql file to insert the data.


PROPERTIES JS :

START : the starting point of the request
LIMIT : the ending point of the request
STEP : the step of the request
SUBSTR : how many characters must we substract from the xmlhttp response (4 = minus 4, but -4 = plus 4)
FILE : if the request is about a file, filename
QUERY : if the request is about a query, query string
TARGET : where to put the result
SCRIPT : PHP script processing the request
MSG : where to put states changes messages
MSG_WAITING : waiting message
MSG_LOADED : loaded message
MSG_READY : ready message
METHOD : request method (POST or GET)
TYPE : the type of request (see below)
ARGS : misc arguments to be given to the SCRIPT. Must be an array.
TIMEOUT : is there a JS timeout on this stack. Useful for a batch process mixed with some user's action, with the noTimeOut::oneShot() method

TYPES JS :
DEFAULT : the default type. can be used to read an array, for example.
FILE_OCTET : request on a file, based on octets
FILE_LINE : request on a file, but based on lines
FILE_PATTERN : request on a file, but based on a pattern matching
DB : request on a DB (readonly, right now)
ONE_SHOT : a one shot request. For example, a user's action updating something.

  Files folder image Files  
File Role Description
Files folder imageclass (2 files)
Files folder imagescripts (6 files)
Accessible without login Plain text file email.php Example example
Plain text file email.txt Data data
Accessible without login Plain text file index.php Example exemple
Accessible without login Plain text file index2.php Example example
Accessible without login Plain text file index3.php Example example
Accessible without login Plain text file index4.php Example example
Accessible without login Plain text file index5.php Example example
Plain text file index6.php Example Example using 2 simultaneous threads
Accessible without login Plain text file readme.txt Doc. doc
Plain text file test.sql Data sql file test
Plain text file test.xml Data test file
Plain text file texte.txt Data test file
Plain text file typewriter.php Example fun example uysing JS TIMEOUT property

  Files folder image Files  /  class  
File Role Description
  Accessible without login Plain text file class.noTimeOut.js Data noTimeOut js class
  Accessible without login Plain text file class.noTimeOut.php Class NoTimeOut PHP class

  Files folder image Files  /  scripts  
File Role Description
  Accessible without login Plain text file arrayFetch.php Appl. script
  Accessible without login Plain text file dbFetch.php Appl. script
  Plain text file emailSend.php Appl. script sending emails
  Accessible without login Plain text file fileFetch.php Appl. script
  Plain text file fileFetchLine.php Appl. script
  Accessible without login Plain text file filePatFetch.php Appl. script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:5,646
This week:3
All time:401
This week:377Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:76%StarStarStarStar
Rank:63