View Full Version : PHP port contention? Please help

06-13-2006, 06:45 PM
I have been trying to Google this for three days with no luck, here is my problem...

I am developing an application that does certain scripted functions for our helpdesk and networking groups and delivers the results via web interface. An example of some of the functionality is port status of a switch, router error tracking, performance monitoring, utilization...that kind of stuff. I'm using snmp to do pretty much everything and it works great and all is good *except* when 2 users try and do something invoking snmp calls at the exact same time. I did a line sniff to see what the deal was and this is what happens as an example:

User (A) requests port speed/duplex settings for a switch on the network, php starts sending out the snmpget calls needed...

User (B) initiates a check for router errors a split second after User (A), while User (A)'s script is still doing its thing. The instant User(B)
does this User(A) stops making the needed snmp calls and just stops. They then need to close out of their web browser and log back in.

User (B)'s request completes without a problem.

I am guessing this is caused by contention for the snmp port and php gets confused. What I don't get is I have some scripts that rely on telnet and they all go out on port 23 and can run at the same time with no problem, why not snmp? My google searches turned up AgentX and smux protocols, but I could not really tell if they are relevant to my problem. Am I trying to do something that snmp is not capable of?

The only idea I had for a work around for this is anytime PHP goes to do an snmp query it can check to see if port 161 is in use, and if it is sleep for a period of time and then try again. Does that sound like it would work? Any input would be greatly appreciated, thanks.

I am running the following configuration on windows 2003

Apache version 2.2.0
PHP version 5.1.2
MySQL version 5.0.18

06-14-2006, 06:33 PM
I have been modifying my code to incorporate a locking mechanism by writing a 'snmp is in use' flag to mysql. But then I had an idea and ran this test:

What I tried doing is to see if another network application that uses SNMP would duplicate the same problem. To my surprise, it didn't. For example we have the Solar winds network management application running on the same machine as my web server. Solar Winds has a circuit utilization gauge that works by making SNMP calls to the router. I pretty much made an exact copy of this functionality, i.e. gathering utilization of the router by making SNMP calls to it. I was able to run both my utilization gauge and the solarwinds utilization gauge at the exact same time and both worked with no problem. So there goes my theory that it is a port contention problem. Maybe the problem is just with PHP itself? Maybe the solarwinds app tests the availability of the port before making a snmp call?