# Bug in xxxxx_close();

- Thread: https://externals.io/message/4465
- Original archive: https://news-web.php.net/php.internals/4465
- Started by Georg Richter on 2003-09-13T19:16:45+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4465 — Georg Richter — 2003-09-13T19:16:45+00:00

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

Hi,

currently I don't have time to analyze or fix it, so I hope someone will take 
a look, it affects most of  db-extensions which support (optional) default 
connection.

Sample:

<?php
  for ($i=0;$i<1000; $i++) {
    $link = mysql_connect("localhost", "foo", "bar");
    mysql_close();
  }
?>

doesn't work correct: 

Function _close_mysql_link which was registered via 
zend_register_list_destructors_ex will be called only 1 time at end of 
script. If you specify mysql_close($link) instead,  everything works fine.

Georg

---

## #4499 — Zeev Suraski — 2003-09-16T16:09:20+00:00

URL: https://externals.io/message/4465#4499 · In reply to: #4465

At 22:16 13/09/2003, Georg Richter wrote:
>Hi,
>
>currently I don't have time to analyze or fix it, so I hope someone will take
>a look, it affects most of  db-extensions which support (optional) default
>connection.
>
>Sample:
>
><?php
>   for ($i=0;$i<1000; $i++) {
>     $link = mysql_connect("localhost", "foo", "bar");
>     mysql_close();
>   }
>?>
>
>doesn't work correct:
>
>Function _close_mysql_link which was registered via
>zend_register_list_destructors_ex will be called only 1 time at end of
>script. If you specify mysql_close($link) instead,  everything works fine.

It's actually by-design(tm).
mysql_close() will close the default link, but $link still holds it 
open.  Every subsequent call to mysql_connect() will reuse this already 
opened link.  If you explicitly use mysql_close($link), or otherwise get 
rid of $link (like unsetting it) - it should work.

Zeev
