note 123569 added to function.pg-connect
| From: | VLroyrenn@php.net | Date: | Wed, 30 Jan 2019 19:31:06 +0000 |
| Subject: | note 123569 added to function.pg-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210146@lists.php.net to get a copy of this message | ||
For what it's worth, it should be noted that, while PHP will generally handle connection-reuse
for you so long as you keep using the same connection strings, as in the following example:
<?php
$before_conn1 = microtime(true);
$db1 = pg_connect($conn_string);
$before_conn2 = microtime(true);
$db2 = pg_connect($conn_string);
$after_conn2 = microtime(true);
echo($before_conn2 - $before_conn1); // Takes ~0.03s
echo("\n");
echo($after_conn2 - $before_conn2); // Takes 0s
?>
...as nice as it would have been, this does not hold true for async connections; you have to manage
those yourself and you can't follow up an async connection with a blocking one later on as an
easy way to wait for the connection process to complete before sending queries.
<?php
$before_conn1 = microtime(true);
$db1 = pg_connect($conn_string, PGSQL_CONNECT_ASYNC);
sleep(1);
$before_conn2 = microtime(true);
$db2 = pg_connect($conn_string);
$after_conn2 = microtime(true);
echo($before_conn2 - $before_conn1); // Takes ~1s
echo("\n");
echo($after_conn2 - $before_conn2); // Takes ~0.025s
?>
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.35 (proxied: 207.96.202.138)
----
Manual Page -- http://php.net/manual/en/function.pg-connect.php
Edit -- https://master.php.net/note/edit/123569
Del: integrated -- https://master.php.net/note/delete/123569/integrated
Del: useless -- https://master.php.net/note/delete/123569/useless
Del: bad code -- https://master.php.net/note/delete/123569/bad+code
Del: spam -- https://master.php.net/note/delete/123569/spam
Del: non-english -- https://master.php.net/note/delete/123569/non-english
Del: in docs -- https://master.php.net/note/delete/123569/in+docs
Del: other reasons-- https://master.php.net/note/delete/123569
Reject -- https://master.php.net/note/reject/123569
Search -- https://master.php.net/manage/user-notes.php