WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World
Connection handling

Connection handling

Internally in PHP a connection status is maintained. There are 3 possible states:

  • 0 - NORMAL
  • 1 - ABORTED
  • 2 - TIMEOUT

When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button. If the PHP-imposed time limit (see set_time_limit()) is hit, the TIMEOUT state flag is turned on.

You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache .conf directive or with the ignore_user_abort() function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate. The one exception is if you have registered a shutdown function using register_shutdown_function(). With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client disconnect you can use the connection_aborted() function. This function will return TRUE if the connection was aborted.

Your script can also be terminated by the built-in script timer. The default timeout is 30 seconds. It can be changed using the max_execution_time php.ini directive or the corresponding php_value max_execution_time Apache .conf directive as well as with the set_time_limit() function. When the timer expires the script will be aborted and as with the above client disconnect case, if a shutdown function has been registered it will be called. Within this shutdown function you can check to see if a timeout caused the shutdown function to be called by calling the connection_status() function. This function will return 2 if a timeout caused the shutdown function to be called.

One thing to note is that both the ABORTED and the TIMEOUT states can be active at the same time. This is possible if you tell PHP to ignore user aborts. PHP will still note the fact that a user may have broken the connection, but the script will keep running. If it then hits the time limit it will be aborted and your shutdown function, if any, will be called. At this point you will find that connection_status() returns 3.


DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
Simple class to create insert and update statements. Independent of the access to the database. Makes handling complex inserts easier - especially when the table structure is liable to change.
Categories : Databases, PHP Classes, PHP
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security



Function to check connection to MySQL and redirect to an error page if an error occurs
Categories : MySQL, PHP, Debugging, Databases
PHP Database connection function with security
Categories : PHP, Databases, MySQL
Connection types : Name <==> Bandwidth
Categories : Misc, Network
Check for an internet connection
Categories : PHP, HTTP
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
Amazon book cover handling
Categories : HTML and PHP, PHP, MySQL, Ecommerce
New functions for PHP3. For those that know Perl, you will recognize a lot of these.All but one deal with array handling. Sorting, splicing, etc.
Categories : Algorithms, Arrays, PHP
A database abstraction layer for the PHP 3.0 ODBC module. It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, PHP, Complete Programs
Generic all purpose class to manage MySQL database connections and queries. Provides for an object-oriented approach to database manipulation. Also allows for easily extending other classes needing database access.
Categories : PHP Classes, PHP, MySQL, Databases
Timezone Handling - A PHP function that wraps several DateTime methods to simplify timezone handling.
Categories : PHP, Date Time
How to make IE open more than the 2 default connections to a server?
Categories : Browsers, General