Here's the plan...
- A PHP script connecting to the local port of the SSH tunnel which forwards to the remote port at the other end using fsockopen() or most likely pfsockopen()
- The PHP script will be run from CLI and I guess I should have some sort of shell script on a cron job to check that the PHP script hasn't stopped for any reason
- I'll need this PHP script to be running permanently, and permanently connected to the socket to receive data whenever it's published by the other end
- Memory and CPU is not a problem as we have plenty of resources on our intranet server (criminally under used). But equally I don't want this script spiralling out of control
- The PHP script will hopefully react to occasional data appearing at the other end of the socket and sometimes inserting or updating data in a MySQL database. Obviously I'll open/close the MySQL connection when necessary, not just leave it hanging.
Are there any PHP functions that can spring into action when data is published at the other end of the socket?
Or would I just loop using fread() like this...
Code: Select all
while (!feof($socket)) {
$output .= fread($socket, 8192);
}What cons/pitfalls should I be aware of when thinking about having a permanently running PHP script connected to a socket?
Cheers, B