PHP Classes
elePHPant
Icontem

PHP Long Running Operations: Execute long operations split in small tasks

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   Screenshots Screenshots   View files View files (30)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2014-05-02 (1 year ago) RSS 2.0 feedNot yet rated by the usersTotal: 323 All time: 6,590 This week: 1,139Up
Version License PHP version Categories  
longops 0.9MIT/X Consortium ...5.2PHP 5, Utilities and Tools, Language
Description Author  

This class can execute long operations split in small tasks.

It executes a portion of long operation and then exits by redirecting the current script to itself, so it executes the next step of the operation until its done.

This way each step does not exceed the PHP default execution time limit.

Each step can be executed by calling a given callback function or executing functions of an eventual sub-class of this class.

Picture of Alexander Selifonov
Name: Alexander Selifonov is available for providing paid consulting. Contact Alexander Selifonov .
Classes: 16 packages by
Country: Russian Federation Russian Federation
Age: 52
All time rank: 602 in Russian Federation Russian Federation
Week rank: 68 Down5 in Russian Federation Russian Federation Down
Innovation award
Innovation award
Nominee: 12x

Winner: 2x

Details provided by the author  
# LongOps: Helper for performing long PHP operations that exceeds max_execution_time limit

If you use "virtual server" hosting for your sites, then you know the problem.
It's name "max_execution_time". Ususaly this means "30 seconds for your PHP code", no more.
And ini_set('max_execution_time',6000) doesn't help, because your ISP won't allow it. So if you want to perform some long operation, like making non-standard data backups or import/export really big data from/to file, you have a problem.

`longOps` is a helper class that allows you to "split" your long-lasting operation to smaller "chunks" and perform the job in "step by step" manner, so every "step" never exceeds php execution limit time.
Additionally you can get the real progress bar of the whole work (not just animated gif) and get a "red button" for stopping it.
All you have to do is rewrite your "long" function so it can resume the job exactly on the point where it was "paused" in previous run. And it should check if "user asked cancel", perform cleanup operation and pass control to the "abortProcess()" class method.

![Demo process screenshot](screenshot.png)

Detailed documentation can be found in the doc folder :

["English documentation"](doc/longops.en.htm)

## Features

* Time-unlimited execution of your PHP scripts
* Job can be cancelled by user at any time (maximun waiting is equal to "time execution", configured by you for one "chunk" of processing.
* Provided javascript module  `longops.jQuery.js` makes all nesessary HTML code for client side (jQuery and jQuery.UI used to show dialog window, progress bar and send AJAX queries)

If you don't use jQuery or jQuery.UI, you'll have to write your own client-side js code.

## License

Code distributed under [MIT license](LICENSE)
Screenshots  
  • screenshot.png
  Files folder image Files  
File Role Description
Files folder imagedemo (7 files, 1 directory)
Files folder imagedoc (2 files)
Files folder imagesrc (2 files)
Accessible without login Plain text file LICENSE Lic. MIT License
Accessible without login Plain text file README.md Doc. Readme

  Files folder image Files  /  demo  
File Role Description
Files folder imageimages (17 files)
  Accessible without login Plain text file demo-backend.php Example Demo Backend (procedural)
  Accessible without login Plain text file demo-class-backend.php Example Demo Backend (OOP)
  Accessible without login Plain text file demo-class.php Aux. frontend demo (OOP)
  Accessible without login Plain text file demo.php Aux. Frontend demo
  Accessible without login Plain text file jquery-ui-custom.css Data css for UI
  Accessible without login Plain text file jquery-ui-custom.min.js Data jQuery UI module
  Accessible without login Plain text file jquery.min.js Data jQuery module

  Files folder image Files  /  demo  /  images  
File Role Description
  Accessible without login Image file animated-overlay.gif Icon for jQuery UI
  Accessible without login Image file ui-bg_flat_0_aaaaaa_40x100.png Icon for jQuery UI
  Accessible without login Image file ui-bg_flat_55_fbec88_40x100.png Icon for jQuery UI
  Accessible without login Image file ui-bg_glass_75_d0e5f5_1x400.png Icon for jQuery UI
  Accessible without login Image file ui-bg_glass_85_dfeffc_1x400.png Icon for jQuery UI
  Accessible without login Image file ui-bg_glass_95_fef1ec_1x400.png Icon for jQuery UI
  Accessible without login Image file ui-bg_gloss-wave_5...9ccc_500x100.my.png Icon for jQuery UI
  Accessible without login Image file ui-bg_gloss-wave_55_5c9ccc_500x100.png Icon for jQuery UI
  Accessible without login Image file ui-bg_inset-hard_100_f5f8f9_1x100.png Icon for jQuery UI
  Accessible without login Image file ui-bg_inset-hard_100_fcfdfd_1x100.png Icon for jQuery UI
  Accessible without login Image file ui-icons_217bc0_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_2e83ff_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_469bdd_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_6da8d5_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_cd0a0a_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_d8e7f3_256x240.png Icon for jQuery UI
  Accessible without login Image file ui-icons_f9bd01_256x240.png Icon for jQuery UI

  Files folder image Files  /  doc  
File Role Description
  Accessible without login Plain text file helpstyles.css Data css for help
  Accessible without login HTML file longops.en.htm Doc. English documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file class.longops.php Class Main backend helper class
  Accessible without login Plain text file longops.jQuery.js Data clientside helper javascript module

 Version Control Unique User Downloads Download Rankings  
 100%Total:323All time:6,590
 This week:0This week:1,139Up