From: Nick Barr <nicky@chuckie.co.uk>
To: A Palmblad <adampalmblad@yahoo.ca>
Cc: pgsql-php@postgresql.org
Subject: Re: PHP memory usage
Date: Mon, 31 May 2004 23:50:43 +0100
Message-ID: <40BBB6C3.8030507@chuckie.co.uk> (raw)
In-Reply-To: <005501c44755$5a851580$97019696@AERS04>
References: <005501c44755$5a851580$97019696@AERS04>
A Palmblad wrote:
> We've been running into some issues with PHP and Postgres, and memory usage.
> On a dual athlon 64, w/ 4 gigs of RAM, PHP 4.3.6, and Postgres 7.4.2 I've
> seen our server start to crawl after some queries returning very large
> result sets. Although large result sets aren't exactly what we want to be
> dealing with, I really want to avoid a situation where a user could disrupt
> our server with certain options to some searches.
>
> I did a quick commandline test, and it looks like PHP starts to eat memory
> during its call to pg_query. By eat memory, I mean use memory well in
> excess of php.ini's memory_limit of 8 megs. (I stop it around 90% of
> available memory usage) Is this acceptable behaviour, or should I report it
> to PHP as a bug? If not, are my only solutions to wrap my selects in
> cursors and/or to use limit?
>
> -Adam Palmblad
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>
>
My guess is that PHP is pulling the entire record set into memory,
something which is not good as you can imagine. The only real solutions
to this are to reduce the size of the record set, or use cursors.
You could reduce the size of the record set by using paging, i.e. only
allowing the user to see say 20 records out of 5000. The way I have
implemented this in the past is to do a COUNT(*) on the entire record
set then use LIMIT 20 OFFSET 200. Alternatively you could use the cursor
to return the data you want to look at.
Hope that almost helps.
Nick
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: nicky@chuckie.co.uk, adampalmblad@yahoo.ca
Subject: Re: PHP memory usage
In-Reply-To: <40BBB6C3.8030507@chuckie.co.uk>
References: <005501c44755$5a851580$97019696@AERS04> <40BBB6C3.8030507@chuckie.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox