php - Is pg_free_result() necessary, even if the result goes out of scope? -


the php docs have pg_free_result():

this function need called if memory consumption during script execution problem. otherwise, result memory automatically freed when script ends.

http://www.php.net/manual/en/function.pg-free-result.php

i (perhaps naively) have expected resource returned call pg_query() garbage collected when goes out of scope.

in hypothetical function this:

function selectsomething () {     $res = pg_query("select blah sometable");     // $res     pg_free_result($res);   // required or not? } 

is necessary call pg_free_result() @ end?

in other words, if call function 1000 times, eat memory store 1000 results?

edit: i'm talking typical case, i.e. pg_connect() instead of pg_pconnect().

as elias van ootegem rightly indicates using persistent connection. persistent connections after query result must continue in memory because may wish gather more data (for example last error).

so comes down practice. if operating in environment have 2m of available memory , script can, @ times, hit 0.1m of memory upper limit 20 concurrent connections calling script. after further web requests going queue or drop. doesn't take genius realise how vulnerable might ddos attack.

best practice, then, empty memory done it. goes programming or scripting ever. when system being stressed , demand high more requests can serviced inside total scope of memory better. if can lower maximum memory footprint of script can increase number of concurrent connections can reasonably try call , increase load script can handle.

the ideal way things release resources can. because don't , seems work anyway during testing no reason not to.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -