2017 © Pedro Peláez
 

library met

MET class provides way to overcome Php's max_execution_time directive by splitting script execution into parts

image

xf3/met

MET class provides way to overcome Php's max_execution_time directive by splitting script execution into parts

  • Tuesday, May 6, 2014
  • by xf3
  • Repository
  • 2 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MET

MET library allows to overcome Php's max_execution_time limit by splitting code execution into parts., (*1)

Description

In case you cannot modify Php's max_execution_time directive and need to execute long-running script, you can use MET to split it and rerun itself each time limit is close with saving done changes., (*2)

Before run, class checks the ability to save data: * Start session for web request * Execute php self_script.php for CLI mode, (*3)

Usage examples

Say you have some script, which imports big database data into file:, (*4)

<?php
require 'met/MET.php';

function mysqlClose() {
    mysql_close();
}

mysql_connect('127.0.0.1', 'root', 'password') || die('Error connecting to Mysql');
mysql_select_db('bigdata_db') || die('Error switching database');

$MET = new MET();

$offset = $MET->value('offset', 0);

$r = mysql_query('SELECT * FROM logs ORDER BY id LIMIT '.$offset.' LIMIT 50');

while($row = mysql_fetch_assoc($r)) {
    appendToLogFile($row);
    ++$offset;
    $MET->check('offset', $offset, 'mysqlClose');
}

mysqlClose();

Here we define $offset variable (0 for first call) and after each row iteration check whether time limit is close., (*5)

If reload is needed, $offset variable is updated to current value and user-defined mysqlClose function is called before exit to close existing Mysql connection., (*6)

The Versions

06/05 2014

dev-master

9999999-dev https://github.com/xf3/MET

MET class provides way to overcome Php's max_execution_time directive by splitting script execution into parts

  Sources   Download

BSD-3-Clause

php max_execution_time