开发者

PHP: TCP Connection Monitoring

开发者 https://www.devze.com 2022-12-11 06:59 出处:网络
I have an application that is used to connect ot a service once a week for a 1 hour session. This session has many requirements, one of which is that we only have one open tcp connection at a time.

I have an application that is used to connect ot a service once a week for a 1 hour session. This session has many requirements, one of which is that we only have one open tcp connection at a time.

Out of the 30 开发者_JAVA技巧or so sessions we've completed we've had 3 sessions where there were multiple tcp connections open during the 1 hour.

I am wondering if there is a method in php which will return the connections state, I have considered using netstat and looking for the ip of the server we connect to and then determin by that status whether its okay to proceed or we should wait. The problem with this is we have plans to purchase more connections in the future and that would result in only 1 connection being passed at a time.

We are using Zend_Http_Client from the zend framework and have tried the following:

unset the client and adapter object explicitly call the adapters close function after the clients request function the last time I did both unset and close the adapter

All the best,

Jason


It may be easiest to exec a netstat command and see if any connections to the remote host are currently established.


you shouldn't try to solve this in the client. limit concurrent connections in the server.


Having revisited this problem I decided to use the bindto option in socket stream options to bind to the same port each time. This should ensure that the previous connection was closed and the port freed.

Testing hasn't been completed but initial results do not show duplicate connections.

http://ca.php.net/manual/en/context.socket.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号