Accueil > > > [PHP5] NOTIMEOUT PACKAGE
[PHP5] NOTIMEOUT PACKAGE
Information sur la source
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
- <?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;
- }
- }
- }
-
-
-
-
-
-
-
<?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;
}
}
}
Historique
- 10 octobre 2006 10:01:42 :
- Tites modifications
- 11 octobre 2006 15:07:05 :
- Modifs mineures sur les messages
- 11 octobre 2006 16:12:28 :
- Modif sur les exceptions
- 11 octobre 2006 17:52:12 :
- Grosses modifications.
Ajout d'un type : FILE_LINE et remplacement de l'ancien par FILE_OCTET, plus juste.
Ajout d'un exemple de FILE_LINE (vraiment du ligne à ligne).
Ajout d'un exemple d'envoi d'email avec le package noTimeOut (email.php, email.txt et scripts/sendEmail.php)
- 12 octobre 2006 10:43:06 :
- Rajout du 'true' dans la méthode xmlhttp::open()
- 20 octobre 2006 10:38:42 :
- Ajout de la gestion de piles de processus, permettant d'effectuer plusieurs traitements en asynchrone.
- 20 octobre 2006 11:56:59 :
- Ajout d'une méthode à la classe js : oneShot. Utilisée pour les traitements Ajax basiques en one shot (1 traitement).
Ajout d'une propriété : ARGS, qui est un tableau JS : il permet de passer autant de variables que nécessaire au script de traitement PHP.
- 20 octobre 2006 12:14:27 :
- Petite optimisation
- 20 octobre 2006 12:56:16 :
- Addition: js timeout
- 24 octobre 2006 10:44:21 :
- Bug sur le TIMEOUT JS corrigé. Maintenant, le timeout JS fonctionne à merveille sans bloquer le navigateur. Cela permet de temporiser la sortie. Je ferai un exemple d'utilisation ludique, pour changer ;-)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
executer une fonction au moment du timeout [ par nlh ]
bonjour, bonjour....en fait j'ai un script tres tres tres long a executer qui se constitue d'une boucle qui bosse sur une base de donnée.....et je vou
Set_time_limit est-il partagé ? [ par grosteack ]
Bonjour à tous !J'ai une question : set_time_limit() est-il partagé à travers les différentes pages d'une même session ?Je m'explique : J'ai une page
Upload FTP [ par caviar ]
Salut à tous,je me posais une petite question concernant le time limit d'execition d'un script php sur le serveur ...Si je veux uploader un fichier de
problème de timeout [ par GoldPegasus ]
j'ai un problème de time out. je demande de réaliser un traitement a une page php mais le traitement dépasse les différents time o
Select limit caractere [ par webmaster51 ]
SalutJe suis en train de faire une page d'accueil,et je dois inserer une actualite.Je n'ai pas de probleme pour selectionner l'actu, mais j'ai un prob
e voudré mettre un lien différent par news [ par Miss1 ]
Miss1salut g fait mis sur mon site des news et je veut mettre un lien pour différents pour c
Timeout flux XML [ par FhX ]
Bon, petit problème avec les flux XML récupéré via simpleXML en PHP5. Comment on défini un timeout sur ce machin ? Parce que j'ai beau essayer avec le
requete DELETE [ par blinix123 ]
Re all ^^ // on supprime toutes les entrées dont le timestamp est plus vieux que 15 minutes// On stocke dans une variable le timestamp qu'il était i
probleme de lancement d'un process java à partir d'un script php [ par salim81 ]
Bonjour J'ai utilisé la commande "exec" dans un script php pour lancer un script shell qui lance à son tour un binaire java, au début il apparait que
Problème avec champ Timestamp [ par stark_2097 ]
Salut,J'ai un petit soucis avec un champ timestamp... je m'y prend surement comme un manche...Dans ma base, le champ "time" est de type Timestamp, on
|
Derniers Blogs
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|