I need to develop HTTP push using php, it sends back a message to the browser every 20 seconds.. that i need to display on the server
Is there any way of implementing http push in php with out using any sockets or library?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure: don’t let your PHP script terminate for as long as you want the connection to remain open. Since you are generating output every 20 sec, the connection is much less likely to timeout.
There are many ways to achieve this including blocking (e.g. sleep() below) or busy waiting, but the simplest solution would be:
You may need to handle unexpected connection termination on the client-side, but this is the jist of it. Check your system configuration to see how many open connections you can handle. (In Apache, see MaxClients)
As for the client-side, see this answer https://stackoverflow.com/a/7953033/329062