Miscellaneous Code
  Home arrow Miscellaneous Code arrow [PHP5] NOTIMEOUT PACKAGE
eWeek
The Best Selling PC Migration Utility.
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

[PHP5] NOTIMEOUT PACKAGE
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-10-09

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    2006/10/24
    - Fixed the JS TIMEOUT bug. Now, it works perfectly.
    2006/10/20
    - Added multiple threads handling via stacks.
    - Added onsShot method, and ARGS property
    noTimeOut package
    @author : Johan Barbier
    @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.








    By : malalam

    <?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 ();
    }
    }
    }
    ?>

    Click to Download File



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! LPI exam 301 prep, Topic 302: Installation and development

    In this tutorial, Sean Walberg helps you prepare to take the Linux Professional Institute Senior Level Linux Professional (LPIC-3) exam. In this second in a series of six tutorials, Sean walks you through installing and configuring a Lightweight Directory Access Protocol (LDAP) server, and writing some Perl scripts to access the data. By the end of this tutorial, you'll know about LDAP server installation, configuration, and programming.
    FREE! Go There Now!


    NEW! Kick-start your Java apps

    To create, test, and deploy a Web-based application or Web service rapidly, you need a proven relational database, a standards-compliant Web application server, and a flexible IDE. Ideally, all these software packages are production-tested, simple to obtain, easy to use, and well integrated with one another. This tutorial shows you how to use IBM-backed open source and free software to kick-start your Java Web-based application development. You'll learn exactly where to download such components, install them, and get them working for you today.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Write REST services

    This tutorial discusses the concepts of REST and the Atom Publishing Protocol (APP) and shows how they apply to services. It also shows how to use Java technology to implement REST/APP-based services.
    FREE! Go There Now!


    NEW! Demystifying the automation of custom controls: Part 2. A step-by-step example of using IBM Rational Functional Tester to automate custom controls

    This tutorial applies the concepts that were covered in the first part of this two-part series to a real-world example.
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway