mysql_unbuffered_query()

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

mysql_unbuffered_query()

Post by Oren »

mysql_unbuffered_query()
First time I hear about this function. I've never seen anyone using this function and after reading the manual it seems to me that it has great advantages, are there any disadvantages/reasons as to why no one is using it (at least I've never seen anyone :P).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

take a look at the user comments.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

This doesn't seem to be implemented in mysqli. Am I right?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

feyd wrote:take a look at the user comments.
If you are talking about the fact that you can't use mysql_num_rows(), I've already read that in the manual and that's not a problem.
If you are talking about something else, please tell me what exactly.

I see no reason why not using it instead of mysql_query(), but since I've never seen anyone using it, I assume there must be a good reason after all.
Does anyone know what this reason might be?

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

~Oren... it basically only works while the connection to the DB is still alive. If you disconnect before processing the result, you lost the ability to do so. Apart from that it seems fairly sensible to use for large resultsets.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

d11wtq wrote:Apart from that it seems fairly sensible to use for large resultsets.
Then why it isn't used at all (I think)?
Since when you close the connection before you finish to work with the database? :?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Oren wrote:
d11wtq wrote:Apart from that it seems fairly sensible to use for large resultsets.
Then why it isn't used at all (I think)?
Since when you close the connection before you finish to work with the database? :?
You may use a DB class which opens a connection while it runs a query then sends you the result and closes the connection. You'd then be working with a buffered result after the connection is closed which would be fine, but with mysql_unbuffered_query() it just wouldn't work. I'm not saying you should use it, I'm just providing an example :) I'd probably make use of this since like you say, a DB connection will usually remain open for the duration of the page request, or at least until you've finished using the DB.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

It may be a good idea to only use mysql_pconnect and mysql_close if you are going to use unbuffered query.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Jenk wrote:It may be a good idea to only use mysql_pconnect and mysql_close if you are going to use unbuffered query.
Yep this is a well known performance booster.
You may use a DB class which opens a connection while it runs a query then sends you the result and closes the connection.
Change to use a destructor to close the connection.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

ole wrote:Change to use a destructor to close the connection.
Never done it in a different way :P
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

you 'should' create a close() method on your DB class incase you ever do want your script to close the connect prior to script termination.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Last I saw/checked, pconnect wasn't much of a speed booster anymore. It's benefits went south after PHP 3, if memory serves.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

<off-topic>"That's feyd, not Feyd, not fyed; just feyd. Pronounced fade. ", good to know... each time I used your name I wasn't sure since I had seen others write it as "Feyd", but I just write the names exactly as they appear in the user's profile :P </off-topic>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

feyd wrote:Last I saw/checked, pconnect wasn't much of a speed booster anymore. It's benefits went south after PHP 3, if memory serves.
Is that true for mysql_pconnect on it's own, or in conjunction with mysql_unbuffered_query()? I'm unable to test atm.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jenk wrote:Is that true for mysql_pconnect on it's own, or in conjunction with mysql_unbuffered_query()? I'm unable to test atm.
I believe it's the use of pconnect at all, mysql_unbuffered_query() or not.
Post Reply