# Add a memory limit in mysql ext

- Thread: https://externals.io/message/36684
- Original archive: https://news-web.php.net/php.internals/36684
- Started by Olivier Bonvalet on 2008-03-30T11:32:58+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36684 — Olivier Bonvalet — 2008-03-30T11:32:58+00:00

URL: https://externals.io/message/36684#36684

Hello,

I often host clients which have "bad" PHP/SQL code ; as for example
a "select *" + mysql_row_nums on a 200Mo table just to count lines...

So I add a little patch to throw a warning in case the result of mysql_query
is larger than a specified limit.
I use the setting "mysql.min_stored_data_before_warn" in php.ini, and the
result is :
[30-Mar-2008 04:39:56] PHP Warning:  mysql_query() [<a 
href='function.mysql-query'>function.mysql-query</a>]: Your query use 
too much memory (202636 o) in /path/to/script.php on line 8

This patch seem "usefull" for me as PHP does not report the queries's memory
consumption. But maybe it should be done in mysqli and PDO extensions to ?

I'm not a "C developper", and the patch use the mysql internal struct, so
it's not really "clean". Maybe we can do it differently.

Thanks

Olivier

PS : sorry for my limited english.

---

## #36702 — Andrey Hristov — 2008-03-31T08:19:30+00:00

URL: https://externals.io/message/36684#36702 · In reply to: #36684

Hi,
Olivier Bonvalet wrote:
> Hello,
> 
> I often host clients which have "bad" PHP/SQL code ; as for example
> a "select *" + mysql_row_nums on a 200Mo table just to count lines...
> 
> So I add a little patch to throw a warning in case the result of 
> mysql_query
> is larger than a specified limit.
> I use the setting "mysql.min_stored_data_before_warn" in php.ini, and the
> result is :
> [30-Mar-2008 04:39:56] PHP Warning:  mysql_query() [<a 
> href='function.mysql-query'>function.mysql-query</a>]: Your query use 
> too much memory (202636 o) in /path/to/script.php on line 8
> 
> This patch seem "usefull" for me as PHP does not report the queries's 
> memory
> consumption. But maybe it should be done in mysqli and PDO extensions to ?
> 
> I'm not a "C developper", and the patch use the mysql internal struct, so
> it's not really "clean". Maybe we can do it differently.

 From 5.3 one can compile ext/mysql and ext/mysqli with mysqlnd (comes 
with PHP) instead of libmysql. mysqlnd uses the Zend MM and thus obeys 
to the memory limit. You can even download ext/mysql and ext/mysqlnd 
from a 5.3 source and replace ext/mysql in your source tree. Rebuild 
configure with buildconf and then configure with --with-mysql=mysqlnd . 
You get the functionality with 5.2 then too. Using mysqli with 5.2 needs 
a small Zend patch (backport of 2 files from 5.3 due toe mysqli's 
persistent connections).

> Thanks
> 
> Olivier
> 
> PS : sorry for my limited english.
> 

Regards,
Andrey
