[php5] notimeout package

Soyez le premier à donner votre avis sur cette source.

Vue 8 001 fois - Téléchargée 582 fois

Description

Ce package est une version...heu...packagée :-) de mes astuces pour éviter le time limit de PHP.
En clair, cela vous permet de faire un gros traitement sans être embêté par le time limit de PHP.
Vous pourrez lire un fichier de 50000 lignes, et l'afficher, même si ça prend 5mn, avec un time limit de 30 secondes, sans aucun problème. Pareil pour une grosse requête.
Le secret ? Les requêtes XMLHTTP (aka Ajax).

Il y a un readme.txt dans le zip, c'est pour l'instant en anglais, je mettrai ça en français quand j'aurai le temps.
De toute façon, 4 fichiers indexX.php vous montreront comment utiliser les 4 types de process disponibles à ce jour dans le package. C'est relativement simple.

N'hésitez pas à me poser des questions si vous rencontrez un problème d'incompréhension.

PS : pour utiliser index2.php vous devrez d'abord créer une table mysql nommée 'tests', et utiliser le fichier sql fourni pour insérer les données.
Ou alors, vous modifiez l'instanciation de la classe pour utiliser une de vos tables :-)

Source / Exemple :


<?php
/**
@author : Johan Barbier <johan.barbier@gmail.com>
@Version : 2006/10/09

  • /
class noTimeOut { private $aProps = array ( 'TYPE' => null, 'DB' => null, 'HOST' => null, 'LOGIN' => null, 'PWD' => null, 'QUERY' => null, 'DBSERVER' => null, 'FILE' => null, 'START' => null, 'LIMIT' => null, 'STEP' => null ); private $aDbServers = array ( 'MYSQL', 'MSSQL' ); private $aTypes = array ( 'DEFAULT', 'FILE_OCTET', 'FILE_PATTERN', 'FILE_LINE', 'DB' ); public function __construct () { // might be useful later } public function __set ($sType, $sVal) { try { if (!array_key_exists ($sType, $this -> aProps)) { throw new Exception ($sType.' is not a valid property'); } } catch (Exception $e) { echo $e -> getMessage (); } try { switch ($sType) { case 'TYPE': if (!in_array ($sVal, $this -> aTypes)) { throw new Exception ($sVal.' is not a valid TYPE value'); } break; case 'FILE': if (!file_exists ($sVal)) { throw new Exception ('File '.$sVal.' has not been found'); } break; case 'DBSERVER': if (!in_array ($sVal, $this -> aDbServers)) { throw new Exception ('DB SERVER '.$sVal.' is not supported'); } break; default : break; } $this -> aProps[$sType] = $sVal; } catch (Exception $e) { echo $e -> getMessage (); } } private static function isNull () { foreach (func_get_args() as $sArg) { if (is_null ($sArg)) { return false; } } return true; } public function flushMe ($aWork = null) { try { if (is_null ($this -> aProps['TYPE'])) { throw new Exception ('TYPE has not been defined'); } } catch (Exception $e) { echo $e -> getMessage (); } try { switch ($this -> aProps['TYPE']) { case 'DB': if (false === self::isNull ($this -> aProps['DB'], $this -> aProps['HOST'], $this -> aProps['LOGIN'], $this -> aProps['PWD'], $this -> aProps['QUERY'], $this -> aProps['DBSERVER'], $this -> aProps['START'], $this -> aProps['STEP'])) { throw new Exception ('DB properties have not been fully defined'); } $mTmp = $this -> getDB (); break; case 'FILE_OCTET': if (false === self::isNull ($this -> aProps['FILE'], $this -> aProps['START'], $this -> aProps['STEP'])) { throw new Exception ('FILE properties have not been fully defined'); } $mTmp = $this -> getFileOctet (); break; case 'DEFAULT': if (false === self::isNull ($this -> aProps['START'], $this -> aProps['STEP'], $aWork)) { throw new Exception ('DEFAULT properties have not been fully defined'); } $mTmp = $this -> getDefault ($aWork); break; case 'FILE_PATTERN': if (false === self::isNull ($this -> aProps['FILE'], $this -> aProps['START'], $this -> aProps['STEP'])) { throw new Exception ('FILE properties have not been fully defined'); } $mTmp = $this -> getFilePat (); break; case 'FILE_LINE': if (false === self::isNull ($this -> aProps['FILE'], $this -> aProps['START'], $this -> aProps['STEP'])) { throw new Exception ('FILE properties have not been fully defined'); } $mTmp = $this -> getFileLine (); break; } return $mTmp; } catch (Exception $e) { echo $e -> getMessage (); } } private function getFilePat () { $sTmp = ''; try { if (false === ($fp = fopen ($this -> aProps['FILE'], 'r'))) { throw new Exception ('Failed to open file : '.$this -> aProps['FILE']); } if ( -1 === (fseek ($fp, $this -> aProps['START'], SEEK_SET))) { throw new Exception ('Failed to modify cursor on : '.$this -> aProps['FILE']); } while (false === ($iEnd = strpos ($sTmp, $this -> aProps['STEP'])) && !feof ($fp)) { $sTmp .= @fgets ($fp, 1024); } $sTmp = substr ($sTmp, 0, $iEnd + strlen ($this -> aProps['STEP'])); @fclose ($fp); } catch (Exception $e) { echo $e -> getMessage (); } return $sTmp; } private function getDefault ($aWork) { try { if (!is_array ($aWork)) { throw new Exception ('Parameter must be an array'); } $aTmp = array (); for ($i = $this -> aProps['START']; $i < $this -> aProps['START'] + $this -> aProps['STEP']; $i ++) { if (isset ($aWork[$i])) { $aTmp[] = $aWork[$i]; } } return $aTmp; } catch (Exception $e) { echo $e -> getMessage (); } } private function getFileOctet () { try { $sTmp = ''; if (false === ($fp = fopen ($this -> aProps['FILE'], 'r'))) { throw new Exception ('Failed to open file : '.$this -> aProps['FILE']); } if ( -1 === (@fseek ($fp, $this -> aProps['START'], SEEK_SET))) { throw new Exception ('Failed to modify cursor on : '.$this -> aProps['FILE']); } if (false === ($sTmp .= @fread ($fp, $this -> aProps['STEP']))) { throw new Exception ('Failed to read file : '.$this -> aProps['FILE']); } @fclose ($fp); return $sTmp; } catch (Exception $e) { echo $e -> getMessage (); } } private function getFileLine () { $sTmp = ''; try { if (false === ($fp = fopen ($this -> aProps['FILE'], 'r'))) { throw new Exception ('Failed to open file : '.$this -> aProps['FILE']); } if ( -1 === (fseek ($fp, $this -> aProps['START'], SEEK_SET))) { throw new Exception ('Failed to modify cursor on : '.$this -> aProps['FILE']); } $iEnd = 0; while ($iEnd < $this -> aProps['STEP']) { $sTmp .= @fgets ($fp); $iEnd ++; } @fclose ($fp); } catch (Exception $e) { echo $e -> getMessage (); } return $sTmp; } private function getDB () { $sDb = strtolower ($this -> aProps['DBSERVER']); try { $rLink = @call_user_func ($sDb.'_connect', $this -> aProps['HOST'], $this -> aProps['LOGIN'], $this -> aProps['PWD']); if (false === $rLink) { throw new Exception ('Failed to connect to host : '.$this -> aProps['HOST']); } if (false === (@call_user_func ($sDb.'_select_db', $this -> aProps['DB'], $rLink))) { throw new Exception ('Failed to select database : '.$this -> aProps['DB']); } if (false === ($rRes = @call_user_func ($sDb.'_query', $this -> aProps['QUERY'], $rLink))) { throw new Exception ('Query failed : '.$this -> aProps['QUERY']); } if (false === (@call_user_func ($sDb.'_data_seek', $rRes, $this -> aProps['START']))) { throw new Exception ('Query failed : '.$this -> aProps['QUERY']); } $iCpt = 0; $aTmp = array (); while (($aRes = call_user_func ($sDb.'_fetch_assoc', $rRes)) && $iCpt < $this -> aProps['STEP']) { $aTmp[] = $aRes; $iCpt ++; } @call_user_func ($sDb.'_close', $rLink); return $aTmp; } catch (Exception $e) { echo $e -> getMessage (); } } } ?> // Classe JS : /** @author : Johan Barbier <johan.barbier@gmail.com> @Version : 2006/10/20
  • /
/** @author : Johan Barbier <johan.barbier@gmail.com> @Version : 2006/10/20
  • /
function noTimeOut () { var aStack = new Array; var aStacks = new Array; function getObject () { if (window.XMLHttpRequest) { var oXmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { var oXmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return oXmlhttp; } function addToData (sStack) { var sData = ''; var iArgs = aStack[sStack]['ARGS'].length; if ( iArgs > 0) { for (var iCpt = 0; iCpt < iArgs; iCpt ++) { sData += '&arg_'+iCpt+'='+aStack[sStack]['ARGS'][iCpt]; } } return sData; } function getDefault (sStack, iStart) { var j = iStart + aStack[sStack]['STEP']; aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_READY']; } /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); } /* parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML += aStack[sStack]['OXMLHTTP'].responseText;
  • /
if (j < aStack[sStack]['LIMIT']) { aStacks.unshift (sStack); aStack[sStack]['START'] = j; checkStack (); } } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var data = 'sType=DEFAULT&iStart='+iStart+'&iStep='+STEP; var iArgs = aStack[sStack]['ARGS'].length; data += addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); } function getDB (sStack, iStart) { var j = iStart + aStack[sStack]['STEP']; aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById(aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById(aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById(aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_READY']; } /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); } //parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML += aStack[sStack]['OXMLHTTP'].responseText; if (j < aStack[sStack]['LIMIT']) { aStacks.unshift (sStack); aStack[sStack]['START'] = j; checkStack (); } } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var data = 'sType=DB&iStart='+iStart+'&iStep='+aStack[sStack]['STEP']+'&sQuery='+aStack[sStack]['QUERY']; data += addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); } function getFile (sStack, iStart) { var j = iStart + aStack[sStack]['STEP']; aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_READY']; } /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); } /* parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML += aStack[sStack]['OXMLHTTP'].responseText;
  • /
if (j < aStack[sStack]['LIMIT']) { aStacks.unshift (sStack); aStack[sStack]['START'] = j; checkStack (); } } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var data = 'sType=FILE_LINE&iStart='+iStart+'&iStep='+aStack[sStack]['STEP']+'&sFile='+aStack[sStack]['FILE']; data += addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); } function getFileLine (sStack, iStart) { var j = iStart; aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_READY']; } /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); } /* parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML += aStack[sStack]['OXMLHTTP'].responseText;
  • /
j += aStack[sStack]['OXMLHTTP'].responseText.length; if (aStack[sStack]['SUBSTR'] != '') { j -= aStack[sStack]['SUBSTR']; } if (j < aStack[sStack]['LIMIT']) { aStacks.unshift (sStack); aStack[sStack]['START'] = j; checkStack (); } } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var data = 'sType=FILE_LINE&iStart='+iStart+'&iStep='+aStack[sStack]['STEP']+'&sFile='+aStack[sStack]['FILE']; data += addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); } function getFilePat (sStack, iStart) { var j = iStart; aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById (aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_READY']; } /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); } /* parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML += aStack[sStack]['OXMLHTTP'].responseText;
  • /
j += aStack[sStack]['OXMLHTTP'].responseText.length; if (aStack[sStack]['SUBSTR'] != '') { j -= aStack[sStack]['SUBSTR']; } if (j < aStack[sStack]['LIMIT']) { aStacks.unshift (sStack); aStack[sStack]['START'] = j; checkStack (); } } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var data = 'sType=FILE_PATTERN&iStart='+iStart+'&iStep='+aStack[sStack]['STEP']+'&sFile='+aStack[sStack]['FILE']; data += addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); } function oneShot (sStack) { aStack[sStack]['OXMLHTTP'].open(aStack[sStack]['METHOD'], aStack[sStack]['SCRIPT'], true); aStack[sStack]['OXMLHTTP'].onreadystatechange=function() { if (aStack[sStack]['OXMLHTTP'].readyState==1) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById(aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_WAITING']; } } if (aStack[sStack]['OXMLHTTP'].readyState==2) { if (aStack[sStack]['MSG'] != '') { parent.document.getElementById(aStack[sStack]['MSG']).firstChild.data = aStack[sStack]['MSG_LOADED']; } } if (aStack[sStack]['OXMLHTTP'].readyState==4 && aStack[sStack]['OXMLHTTP'].status == 200) { /**
  • DOM version, but it does not allow to read HTML tags, or, at least, I did not manage to do it
*
  • /
/* if (!parent.document.getElementById (aStack[sStack]['TARGET']).hasChildNodes()) { var oNode = parent.document.createTextNode (aStack[sStack]['OXMLHTTP'].responseText); parent.document.getElementById (aStack[sStack]['TARGET']).appendChild (oNode); } else { parent.document.getElementById (aStack[sStack]['TARGET']).firstChild.appendData (aStack[sStack]['OXMLHTTP'].responseText); }
  • /
parent.document.getElementById(aStack[sStack]['TARGET']).innerHTML = aStack[sStack]['OXMLHTTP'].responseText; checkStack (); } } aStack[sStack]['OXMLHTTP'].setRequestHeader("Content-type", "application/x-www-form-urlencoded"); data = addToData (sStack); aStack[sStack]['OXMLHTTP'].send (data); checkStack (); } function getData (sStack, sType) { var bGo = false; switch (sType) { case 'DEFAULT': getDefault (sStack, aStack[sStack]['START']); break; case 'FILE_OCTET': getFile (sStack, aStack[sStack]['START']); break; case 'FILE_LINE': getFileLine (sStack, aStack[sStack]['START']); break; case 'FILE_PATTERN': getFilePat (sStack, aStack[sStack]['START']); break; case 'DB': getDB (sStack, aStack[sStack]['START']); break; case 'ONE_SHOT': oneShot (sStack); break; } } function checkStack () { var iLen = aStacks.length; if (iLen > 0) { var sStack = aStacks[iLen - 1]; __checkStack = function () { var sType = aStack[aStacks[iLen - 1]]['TYPE']; aStacks.pop (); getData (sStack, sType); } if (aStack[sStack]['TIMEOUT'] > 0) { setTimeout ('__checkStack()', aStack[sStack]['TIMEOUT'] ); } else { __checkStack (sStack, iLen); } } } this.declareStack = function (sStack) { aStack[sStack] = new Array; aStack[sStack]['START'] = aStack[sStack]['LIMIT'] = aStack[sStack]['STEP'] = aStack[sStack]['FILE'] = aStack[sStack]['QUERY'] = aStack[sStack]['TARGET'] = aStack[sStack]['SCRIPT'] = aStack[sStack]['MSG'] = aStack[sStack]['SUBSTR'] = ''; aStack[sStack]['METHOD'] = 'POST'; aStack[sStack]['TIMEOUT'] = 0; aStack[sStack]['ARGS'] = new Array; aStack[sStack]['MSG_WAITING'] = 'Loading'; aStack[sStack]['MSG_LOADED'] = 'Loaded'; aStack[sStack]['MSG_READY'] = 'OK'; } this.startWork = function (sStack) { aStack[sStack]['OXMLHTTP'] = getObject (); var iLen = aStacks.length; aStacks[iLen] = sStack; checkStack (); } this.initialize = function (sStack, sType, mValue) { if (!aStack[sStack]) { return false; } switch (sType) { case 'START' : aStack[sStack]['START'] = mValue; return true; break; case 'LIMIT' : aStack[sStack]['LIMIT'] = mValue; return true; break; case 'STEP' : aStack[sStack]['STEP'] = mValue; return true; break; case 'SUBSTR' : aStack[sStack]['SUBSTR'] = mValue; return true; break; case 'FILE' : aStack[sStack]['FILE'] = mValue; return true; break; case 'QUERY' : aStack[sStack]['QUERY'] = mValue; return true; break; case 'TARGET' : aStack[sStack]['TARGET'] = mValue; return true; break; case 'SCRIPT' : aStack[sStack]['SCRIPT'] = mValue; return true; break; case 'MSG' : aStack[sStack]['MSG'] = mValue; return true; break; case 'MSG_WAITING' : aStack[sStack]['MSG_WAITING'] = mValue; return true; break; case 'MSG_LOADED' : aStack[sStack]['MSG_LOADED'] = mValue; return true; break; case 'MSG_READY' : aStack[sStack]['MSG_READY'] = mValue; return true; break; case 'METHOD' : if (mValue != 'POST' || mValue != 'GET') { return false; } aStack[sStack]['METHOD'] = mValue; return true; break; case 'TYPE': aStack[sStack]['TYPE'] = mValue; break; case 'ARGS': aStack[sStack]['ARGS'] = mValue; break; case 'TIMEOUT': mValue = parseInt (mValue); if (false == isNaN (mValue)) { aStack[sStack]['TIMEOUT'] = mValue; } else { return false; } break; default: return false; break; } } }

Codes Sources

A voir également

Ajouter un commentaire

Commentaires

Messages postés
89
Date d'inscription
samedi 25 mai 2002
Statut
Membre
Dernière intervention
5 décembre 2009

Ola
Ca peut fonctionner pour la génération d'un mega fichier zip ?
Messages postés
10840
Date d'inscription
lundi 24 février 2003
Statut
Modérateur
Dernière intervention
2 mars 2010
21
Oui tu as raison, mais au moment où j'ai codé cette classe, je voulais voir ce que cela donnait de gérer les exceptions interception comprise dans la classe.
En fait, ça ne sert à rien si ce n'est à perdre des ressources pour rien...faudra que je recode ça.
Alakhnor => l'utilisation de ces classes passent nécessairement par une revisite de ton code. Il faut le voir autrement : la boucle est gérée par du javascript, c'est tout.
Poutr php4, tu dois pouvoir réécrire la classe php...à priori. Rien de vital ne tire partie des spécificités PHP5.
Messages postés
2350
Date d'inscription
mercredi 13 octobre 2004
Statut
Membre
Dernière intervention
18 avril 2015
3
Etrange, je ne l'aurais pas codé comme ca cette classe.
Enfin si, mais au niveau des try{}catch() non.


J'aurais dégagé les try{}catch() des méthodes pour commencer.
Théoriquement, le try{}catch() se fait lors d'un appel de méthode et pas dans la méthode elle même. Sauf si c'est pour appeler une méthodes privée/protégée.

Ex :
# public function __set ($sType, $sVal) {
# try {
# if (!array_key_exists ($sType, $this -> aProps)) {
# throw new Exception ($sType.' is not a valid property');
# }
# } catch (Exception $e) {
# echo $e -> getMessage ();
# }

Ce que j'aurais fait :
public function __set($var, $val) {
if ( !array_key_exists($var, $this -> aProps) )
throw new GetSetException($var, 'set');
// suite...
}

Et quand tu appèles ta classe de l'extérieur :
try {
$maclasse = new noTimeOut;
$maclasse->timeout = 360;
// etc..
} catch ( GetSetException $gs ) {
die ( $gs->getMessage() );
} catch ( Exception $e ) {
die ( $e->getMessage() );
}

Par contre (voila la suite ^^) :
#public function flushMe ($aWork = null) {
# try {
# switch ($this -> aProps['TYPE']) {
# case 'DB':
# if (false === self::isNull ($this -> aProps['DB'], $this -> aProps['HOST'], $this -> aProps['LOGIN'], $this -> aProps['PWD'], $this -> aProps['QUERY'], $this -> aProps['DBSERVER'], $this -> aProps['START'], $this -> aProps['STEP'])) {
# throw new Exception ('DB properties have not been fully defined');
# }
# $mTmp = $this -> getDB ();
# break;

switch ($this -> aProps['TYPE']) {
case 'DB':
if ( !self::isNull ($this -> aProps['DB'], $this -> aProps['HOST'], $this -> aProps['LOGIN'], $this -> aProps['PWD'], $this -> aProps['QUERY'], $this -> aProps['DBSERVER'], $this -> aProps['START'], $this -> aProps['STEP']) )
throw new IssetException('DB');
try {
$mTmp = $this -> getDB ();
} catch ( Exception $e ) {
die ( $e->getMessage() );
}
break;
// Etc...

try {
$maclasse = new noTimeOut;
$maclasse->timeout = 360;
$maclass->flushMe();
// etc..
} catch ( GetSetException $gsE ) {
die ( $gsE->getMessage() );
} catch ( IssetException $iE ) {
die ( $iE->getMessage() );
} catch ( Exception $e ) {
die ( $e->getMessage() );
}

Voila comment je l'aurais joué. J'aurais étendu la classe d'exception pour chaque cas :)
Autrement, ton try{}catch() ne sert pas à grand chose dans une classe :)
Messages postés
2
Date d'inscription
dimanche 4 mars 2007
Statut
Membre
Dernière intervention
5 mai 2007

J'aimerais pouvoir utiliser ces classes. Malheureusement, je me heurte à 2 problèmes:
- je dois développer en php4
- mon programme est une boucle effectuant un certains nombre de traitements incluant des requêtes vers FlickR calculées par le reste. Je ne vois pas trop comment déporter des traitements et les traiter dans la classe php.
Messages postés
10840
Date d'inscription
lundi 24 février 2003
Statut
Modérateur
Dernière intervention
2 mars 2010
21
Merci, c'est très gentil :-)
Afficher les 45 commentaires

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.