Web Hosting Talk







View Full Version : making PHP scripts talk to each other


pclown
10-27-2008, 12:07 PM
making PHP scripts talk to each other

I'm currently trying to write a simple real-time messaging program using javascript and PHP and don't want to use continuous polling to receive messages. My plan is to make the javascript submit a get request to phpscript1 whenever it receives a message, then make the php not respond until it receives a message from the other person who will send a post request to phpscript2. The problem is then to make phpscript1 somehow know when phpscript2 has received a message without using some form of continuous polling. I feel there must be a way to do this because there are so many other websites which seem to do the same thing but I don't really know what. Various sources have suggested that it may be possible using port scanning or something but this seems to conflict with my fairly limited understanding of ports.

Syphic
10-27-2008, 01:13 PM
You could write a client/server socket script with php but then you will have to have a daemon running at all times on the backend of your site which is basically the same as polling the script every few seconds. This is how true real time chats work; or at least form what I have researched and learned.





__________________TeachExplain.com - A calculator which shows step by step how to solve math problems.Syphic.com - My network of websites live, beta, and in progress

onclick
10-28-2008, 08:50 AM
it's either ajax message pulling or PHP socket server like my friend said.

mod_webhosting
10-28-2008, 11:28 AM
Whatever solution you choose, make sure that PHP script doesn't wait forever to receive that second POST request. Otherwise you might end up with lot of zombie scripts taking up your memory.

cygnusd
10-29-2008, 08:59 PM
you might want to check out http://activemq.apache.org/ajax.html

chandrachur
10-29-2008, 10:12 PM
I think you can run a cronjob in the server for port scanning to check any response from the phpscript2. This is one the solutions as you do not want the thing to run like a chat program or a polling script.





__________________www.myetutor.ca - Need help in Math and Physics for free? Experience the effect of Online Tutoring...sitting at the comfort of your home!