Hi,

I don't know if there is some name for this but what I want to create a script in php which runs in the background and capable of sending and receiving messages.

This is what I want to do exactly:

  1. Listen to a URL http://site1.com through xmpp protocol.
  2. Whenrever there is a message from site1.com, I should send it to http://site2.com as GET
  3. Listen to http://site2.com for a response (site2 may take >=30mins to respond to message we sent in step2)
  4. If a GET a response from site2.com, I should send the message to http://site1.com through xmpp.

This is what I've done:

  1. Using XMPPHP library, listening to site1.com consistenly through infite while loop.
  2. Whenver there is a message, i'm using file_get_contents() to push message to site2.com
  3. Now, I'm struck here. I don't how listen to this site2.com on GET now, as my script is already running and listening to site1.com
  4. Its easy to send a message to site1.com. The problem is only 3.

---
Any idea how I could solve this or any other alternative(better) way I could do this? Any help is appreciated.

PS: I don't have access to both site1.com and site2.com except thier urls for sending and receving.

you, sir, are building a proxy (at least, that's what it sounds like to me). Feel free to read about that: http://en.wikipedia.org/wiki/Proxy_server

There are many PHP proxy scripts you can snag. Glype, I believe, is very popular. There are other alternatives, including some from google.

However, the way you are going about it is probably not the best. PHP is already a giant while loop wiating for data on port 80 (or 443, or whatever port you plop a listener on). There is no need to reinvent the wheel.

Depending on how you are getting your data from Site: 1, you have many options available. Right now, you seem to be trying a "polling" method, which is very traffic intensive, and sucks up a lot of resources just to check if something has changed. If you are connecting to a database, you most certainly don't want to have a while loop spamming a read off those tables non-stop, as that will eventually bring the poor Site: 1 to its knees (and may get you black listed from the host anyway).

It may provide a better answer if you either provide sample code, or explain in further detail what you are attempting to accomplish.

No, Here is a image of the explanation if that helps.

My client wants me to be a middle man between these things as they also need some other data along with API.

So, he wants me create an API kind of thing where I provide him the data from the third party API and also other related data.

http://i.imgur.com/WmkoJcO.png

--

No. I'm not connected to a database, just transmitting the data.
Like I said I'm using XMPP to talk to site1.com. It is a command line script & runs in background. Inside the while loop, I keep pushing the messages to site2 via GET but I don't know how to receive messages from site2 while the script is running.

I know it is not so efficient doing thing stuff in PHP, but I want to go with this now. Later on, we'll use java or something else.

Let me understand , you don't want to HOLD your script while you are waiting to receive the response of GET or you don't know at all how to get the response? In any case what method do you use in order to create those GET requests ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.