note 32261 added to function.mysql-unbuffered-query

From: Date: Wed, 21 May 2003 21:45:49 +0000
Subject: note 32261 added to function.mysql-unbuffered-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-48792@lists.php.net to get a copy of this message
Regarding bailing on a really large result, while doing an unbuffered query, there _is_ a way to do this: kill the thread and exit your processing loop. This, of course, requires having a separate database link. Something like below does the trick: // a db link for queries $lh = mysql_connect( 'server', 'uname', 'pword' ); // and a controller link $clh = mysql_connect( 'server', 'uname', 'pword', true ); if ( mysql_select_db ( 'big_database', $lh ) ) { $began = time(); $tout = 60 * 5; // five minute limit $qry = "SELECT * FROM my_bigass_table"; $rh = mysql_unbuffered_query( $qry, $lh ); $thread = mysql_thread_id ( $lh ); while ( $res = mysql_fetch_row( $rh ) ) { /* do what you need to do * ... * ... */ if ( ( time() - $began ) > $tout ) { // this is taking too long mysql_query( "KILL $thread", $clh ); break; } } } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-unbuffered-query.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32261 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32261&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32261&report=yes

« previous php.notes (#48792) next »