Since you don't need to put up a server, you can just use fsockopen. If I recall correctly, passing the timeout argument as 0 means no timeout... If you use the cli version of php, you can just enter `php -q myscript.php &` on the command line (doubt this works w/ m$...). The ampersand tells the os to run the process in the background. If feof($connection) is true, just fsockopen a new connection.
Odds are, however, that the ISP doesn't have the cli version... If not, check to see if pcntl was enabled (if so, php.net/pcntl_fork). Your biggest problem will prolly be the ISP's max execution time (which you will probably not be able to change) It is entirely possible that, since you don't really control the box, you won't be able to do this via php. You may have to resort to C. If so, my advice would be (a) hire someone else to write the program, or (b) buy a beginning C book, and get very very cozy with google, and the `man` and `info` commands. BSD socket interface is a PITA, but IMHO not as bad as winsock... the PHP socket functions are basically the BSD socket interface, so learn them first (easier, and it'll help a lot trying to decipher the C version) On Thursday 17 July 2003 02:17 pm, René Fournier wrote: > (Okay, now you're prepared...) > > I need to write a little program that opens and maintains a TCP socket > connection to a server across the Internet. This little program would > wait for messages from the server it's connected to, then record those > messages and send a kinda of acknowledgment "Got it". > > I've written a fair amount of PHP scripts for web sites, but nothing > that would run in the background, independently say of a web browser or > server. In other words, I don't really know what I'm doing, or where to > start. I've looked at PHP.net's socket docs, but everything seems to > scream experimental, use at own risk, etc. This little program, while > operationally simple, needs to be very reliable. For example, if the > socket connection dies for some reason, it would know to open a new > one. Or if the server doesn't acknowledge my little program's periodic > "Hey, you still there"-type pings, it would close the connection and > reopen a new one. (In fact, at the end of this message I'll list the > basic operation and flow of the little program as stated by the company > running the server to which I would connect.) > > In any case, what I want to know is, can this be done with PHP on a > run-of-the-mill PHP-savvy ISP? Or would I need something more > configurable? Would I need to learn C and compile a UNIX program to do > this? Any ideas where to start? Resources, links? Anything would be > much appreciated.... Thanks very much in advance. > > Here is how the little program should function, according to the > Company: > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > The following describes the basic operation and flow needed within the > DC: > > Setup and open tcp socket using IP address and port number13 > Send a Password_DS to the DS > Send a Resend_DS to the DS > Enter infinite loop: > Wait for messages from the DS > Upon receipt of a Send_DS from the DS > Store message contents appropriately > Send a Send_DS_Ack to the DS > Send message contents to other CSP applications > Upon receipt of a Ping_DS > Respond with a Ping_DS_Ack > Upon receipt of a Status_DS > Respond with a Status_DS_Ack > If needed, send message to other CSP process(es) > Periodically, send a Ping_DS to the DS > If the Ping_DS transmit fails > Clean-up and restart the socket connection > If a Ping_DS_Ack is not received from the DS > Clean-up and restart the socket connection > > In this sequence, the data formats for the messages must follow the > requirements > shown earlier. I.e., the Startup_DS message must include the correct > client type; > the Send_DS_Ack messages must include the hostID and sequenceID data, > etc. The > data contents received by the DC will usually be formatted and > forwarded to > other CSP-internal procedures for further processing. > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > ...Rene -- "We humans are the species that makes things. So when we find something that appears to be beautifully and intricately structured, our almost instinctive response is to ask, 'Who made that?' The most important lesson to be learned if we are to prepare ourselves to approach the universe scientifically is that this is not the right question to ask. It is true that the universe is as beautiful as it is intricately structured. But it cannot have been made by anything that exists outside it, for by definition the universe is all there is, and there can be nothing outside it. And, by definition, neither can there have been anything before the universe that caused it, for if anything existed it must have been part of the universe. So the first principle of cosmology must be 'There is nothing outside the universe'." -Lee Smolin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php