Description:
------------
I have a weird happening.
On Windows, I executed below the script.
{code}
<?php
$pdo = new PDO('pgsql:host=xxxxxxxx;dbname=postgres;port=5432', 'postgres', 'mypassword');
sleep(600);
{code}
After 10 seconds, I stopped the script by SIGINT(CTRL+C).
And then I saw the 'netstat' in Postgresql server.
I expected not to see the 'established connection'.
However, I saw the 'established connection'.
{code}
tcp 0 0 xxx.xxx.xxx.xxx:5432 xxx.xxx.xxx.xxx:64682 ESTABLISHED 26620/postgres: pos
{code}
Why it happened?
P.S
On Linux(centos7), it was the same that I expected.
(could not see 'established connection')
Test script:
---------------
<?php
$pdo = new PDO('pgsql:host=xxxxxxxx;dbname=postgres;port=5432', 'postgres', 'mypassword');
sleep(600);
Expected result:
----------------
close connection(not established)
Actual result:
--------------
tcp 0 0 xxx.xxx.xxx.xxx:5432 xxx.xxx.xxx.xxx:64682 ESTABLISHED 26620/postgres: pos

Pull Requests

History

Please try again and wait 50 seconds and run `netstat` again and then again at 60 seconds (so 2 `netstats`, one 60 seconds after socket created and one 60 seconds after database connection closed).
Just checking, is the database server localhost (127.0.0.1) ??

Windows doesn't reallocate the port# for 240 seconds(by default) after the connection is closed -- to ensure that, the connection is left in that table. This is in case additional packets are sent by the other side after the connection is closed on this side.
This time is controlled by the registry key: HKEY_LOCAL_MACHINE \System \CurrentControlSet \services \Tcpip \Parameters
For higher web server performance, you can decrease this time. Otherwise, its fine. Its just a behavior difference (though behavior specified in IETF RFC 793).
Without more info, I assume this is what the issue here is... in which case, this can be closed as not a bug.
Maybe this should be in the PHP manual for socket() (since its is a generic TCP behavior not just PgSQL).