473,612 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pear DB and memory usage, strange...

Hi

I have a problem with pear DB

my code :

for ($i=0;$i<100000 ;$i)
{
$sql = "select id from table where id=x";

$db->query($sql);
}

if i run this code memory usage grow up, during for loop

but if i use mysql_query($sq l) instead of $db->query($sql), memory
usage stay the same during all for loop

Have you an idea to solve my problem ?

vincent
Jul 17 '05 #1
3 2204
sa*******@gmail .com (Vincent) wrote in message
news:<77******* *************** ****@posting.go ogle.com>...

I have a problem with pear DB

my code :

for ($i=0;$i<100000 ;$i) {
$sql = "select id from table where id=x";
$db->query($sql);
}

if i run this code memory usage grow up, during for loop

but if i use mysql_query($sq l) instead of $db->query($sql), memory
usage stay the same during all for loop
This is a rather well-known deficiency in memory management in PHP 4.
Memory allocated to objects is not released until the end of script's
execution.
Have you an idea to solve my problem ?


Don't use OOP in general and database abstraction layers in particular.
Another option is to switch to PHP 5, where this problem has purportedly
been solved.

Cheers,
NC
Jul 17 '05 #2
Nikolai Chuvakhin wrote:
for ($i=0;$i<100000 ;$i) {
$sql = "select id from table where id=x";
$db->query($sql);
}

if i run this code memory usage grow up, during for loop

but if i use mysql_query($sq l) instead of $db->query($sql), memory
usage stay the same during all for loop


This is a rather well-known deficiency in memory management in PHP 4.
Memory allocated to objects is not released until the end of script's
execution.


To be more accurate, PHP4 releases memory taken by objects created from
simple user classes before the script ends - i.e. when variable is no
longer used or it is being assigned a new value. But it doesn't work the
same way when you have an object from a more complex class structure.
Exactly what causes it - I don't know.
Have you an idea to solve my problem ?


Don't use OOP in general and database abstraction layers in particular.
Another option is to switch to PHP 5, where this problem has purportedly
been solved.


Yes, at least with what I have tested, memory usage still starts to grow,
but levels out at some point. In my testing, it's definitely not nearly as
efficient as using variables and functions.

Even if OP were to switch to and run the script in PHP5, it would be a good
idea to first try the script both ways (with and without objects in the for
loop) and track the memory usage during that for loop to help him decide if
using objects is right for him.
Jul 17 '05 #3
> if i run this code memory usage grow up, during for loop

but if i use mysql_query($sq l) instead of $db->query($sql), memory
usage stay the same during all for loop

Have you an idea to solve my problem ?


How are the memory requirements on your system with the following alternative?

// http://pear.php.net/package/DB/docs/...#methodprepare
$statement = $db->prepare('selec t x from table where id = ?');

for ($i = 0; $i < 100000; ++$i)
{
$result = $db->execute($state ment, $i);
}

$db->freePrepared($ statement);
Regards,
Markus
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1866
by: Joe Randstein | last post by:
Hi! I now use the DB classes from PEAR with mysql. Do I still have to use addslashes? I ask, because I get some very strange results, I get slashes in front of every " and they get saved in my database :-( Now my hoster has turned magic_quotes_gpc on anyway. As a workaround: On a PHP-environment where magic_quotes_gpc is turned on, can I do stripslashes on every request-data without danger?
0
1537
by: Jay Donnell | last post by:
I just installed Getopt via pear and pear stopped working. No matter what I put as arguments I get the usage instructions: # pear list-installed Usage: pear command <parameters> Type "pear help options" to list all options. .... Clearly the version of pear doesn't like the newest version of Getopt.
3
7233
by: junkmail | last post by:
on a win 2k server apparantly it is saying i dont have it. or it cant find it. im using mySQL 4.1 php 4.3.x apache 3.0.53 im new to php and am doing some tutorials, but when i run the sripts it tells mea it can not run pear/soap, because it can not be found.the book im learning form does not tell me how to install or configure this extension. so now im looking for help.
2
4851
by: Gonzalo | last post by:
Just upgraded php (5.0.3) - compiled from source. I'm trying to upgrade & install some Pear packages but get the following error: $ pear upgrade pear downloading PEAR-1.3.5.tgz ... Starting to download PEAR-1.3.5.tgz (108,423 bytes) ..........................done: 108,423 bytes PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
2
3048
by: David | last post by:
I have a book which had code that includes the line: require 'DB.php'; I know that this is from the PEAR code modules, but when I downloaded them and unpacked the directory, they "DB.php" module does not exist. Is this out of date or do I need to go somewhere else to get this extra module? Thanks
3
2195
by: David | last post by:
I installed the Pear program and set the include path in php.ini to point to the pear dir. I have a program which <? require_once("DB.php"); ?> This produces the error "Class 'PEAR_Error' not found in c:\PHP\pear\PEAR\DB.php on line 868"
20
4211
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the memory usage drops to a couple hundred KB. Why? Is there anything I should to to prevent this? I have compiled in release and deactivated all forms of debugging, I think! Thanks, Philip
0
3076
by: greg.novak | last post by:
I am using Python to process particle data from a physics simulation. There are about 15 MB of data associated with each simulation, but there are many simulations. I read the data from each simulation into Numpy arrays and do a simple calculation on them that involves a few eigenvalues of small matricies and quite a number of temporary arrays. I had assumed that that generating lots of temporary arrays would make my program run slowly,...
2
4107
by: manojmohadikar2008 | last post by:
Hi All, We are observing a serious issue with the memory usage of Queue and its very critical issue which needs to be fixed. We have an application which runs two threads i.e. a Producer and a Consumer thread. The Producer thread (Enqueue) inserts some heavy user defined object in the Queue. The Consumer thread (Dequeue) deletes one object from the Queue and processes it. When we monitored the memory usage of this application in Task...
0
8115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8568
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6082
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4111
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2555
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1416
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.