简体   繁体   中英

PHP Socket Server/Client

I have read a few good articles about coding a socket server but thought I would ask here to see if there is any further knowledge/ideas about what I actually need.

I run multiple websites for clients all running off the same server, connecting to the same DB etc. Each client website has a form where users can submit their details for services we offer. These users are spread out across the world but what I am wanting to build is a monitoring system where my interface displays the users IP address, client website they are on, the page they are on etc. From the IP I will do a country/state look up (I know its not 100% accurate but close enough is good).

I would like the visiting site to send a packet to the socket server which in turns sends the output information to my screen in real time (after I perform some actions). I guess you could say I am building a mini NOC to monitor website activity. I would also like the output information to be most recent activity at top of screen but also show a scroll bar to view all activity.

Are sockets the best mechanism for this system? Any other suggestions or tutorials on how to achieve the outcome?

Many thanks.

Before you begin down this road, have you checked out the realtime part of Google Analytics ? It does most of what you are looking for.

When someone is visiting your site, you aren't typically going to have a persistent connection. I'd suggest that rather than creating one, parse your server logs or store user information in a database, and query for the last x minutes of visitors.

For updating the viewing page that you are on in realtime, Web Sockets are best for this if you need very fast response time, but are currently quite the hassle to do in PHP . In addition, browser support isn't very wide. If you insist on using PHP, I'd recommend polling over AJAX. Otherwise, look into using Node.JS with Socket.IO . Socket.IO wraps up a lot of similar methods to web sockets to get the same effect with little effort. Still use PHP for your application... just use the Node.JS/Socket.IO part for your monitor interface.

Finally, I'd suggest questioning again why you might want this. You can spend a lot of time on a project like this, and the truth is that your analytics data over time is far more valuable than a snapshot when you are looking at it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM