tags:

views:

56

answers:

1

Now, I am developing an SNMP webserver and I want to get the data from MIB in the Windows to insert in the MySql data base. I use SNMP connection which provide in PHP, so I want my php script always run and no interface in the background for updating the database. Can I do like this or there are the better way to do. Please, help me.

+1  A: 

You'll need something like a daemon in php, although this isn't the best way to do it, it's possible. Just fire your php script from the command line (php CLI environment) and fork it off the console as new process. The starting depends on your OS, but in either case a simple console script will do the job. Then you only have to make sure your php script never finishes. Use this never ending script to poll your SNMP agent and write the values to MySQL. Design another bunch of PHP scripts for reading from the DB and displaying the values in a webpage.

Note: PHP was not designed for such a purpose, i.e. implementing a resident daemon which behaves like a kind of application, so you may easily run into difficulties regarding memory consumption and processing (no multi-threading!).

I recommend to use another language for the daemon service i.e. Java. There's a free open source library SNMP4j which is easy to use and let you realize your poller in minutes (I would even say it's much more mature than the SNMP extension in PHP).

jek
thank you very much for your suggestion, I will try it.
PlodPla