My question deals with establishing a connection. It appears that
establishing a new connection using fsockopen() would not connect me to
the originator's session and I don't know how to re-use the existing
connection.
My question deals with establishing a connection. It appears that
establishing a new connection using fsockopen() would not connect me to
the originator's session and I don't know how to re-use the existing
connection.
I was not able to find the answer to my question in the CURL
documentation. I understand that it may not be possible to do this
using php.
My script would get a request via POST from a client. The client would
wait for response. In order for me to respond, I need to get a handle
to the initial connection. This may not be possible. I think that this
type of situations are usually handled via a coordinating daemon.
>I was not able to find the answer to my question in the CURL[color=blue]
>documentatio n. I understand that it may not be possible to do this
>using php.
>
>My script would get a request via POST from a client. The client would
>wait for response. In order for me to respond, I need to get a handle
>to the initial connection.[/color]
If your page is running under PHP, you already have a connection.
Output something (say, with echo or header() or something).
[color=blue]
>This may not be possible. I think that this
>type of situations are usually handled via a coordinating daemon.[/color]
If you are making an outgoing connection to something (with, say,
fopen on a remote URL) and want to copy the response IT sends to
the request you got, look at fpassthru().
I am working on a php script that will receive database requests from
remote URL's. The script's job is to execute the request and send the
results back to the requester.
The requester does the following:
1. Open a connection using fsockopen().
2. Post headers and request using fputs()
3. Read response using fgets()
This works fine. I am using a class that does that in other
applications communicating with applications that successfully send the
responses back. I am trying to write a script that also sends responses
back and that is where I am running into difficulties
The problem script obtains the request from $_POST. That also works.
The question is how do I send the response back to requester so that it
can read it using fgets(). Or, more specifically, how do I establish a
connection back to the requester so that I can send the response.
If I use fsockopen() to establish a connection to the requesting URL,
it appears that it would not be communicating with the same session. I
also don't see a way to get a handle to the existing connection that
was created by the requester.
>My question is not well stated. Let me try again.[color=blue]
>
>I am working on a php script that will receive database requests from
>remote URL's. The script's job is to execute the request and send the
>results back to the requester.
>
>The requester does the following:
>
>1. Open a connection using fsockopen().
>2. Post headers and request using fputs()
>3. Read response using fgets()[/color]
Forget these details. Pretend the situation is: Someone typed the
URL into a browser or clicked on a link. Then do what is appropriate:
output something. Ok, you're outputting xml instead of html. Big
deal. Text is text. When you get a request, it's difficult to
tell that it's *NOT* someone with a browser, and you shouldn't try
to distinguish the difference anyway.
[color=blue]
>This works fine. I am using a class that does that in other
>applications communicating with applications that successfully send the
>responses back. I am trying to write a script that also sends responses
>back and that is where I am running into difficulties
>
>The problem script obtains the request from $_POST. That also works.
>The question is how do I send the response back to requester so that it
>can read it using fgets().[/color]
Don't even think about trying to establish a connection, the other
end already did it. OUTPUT SOMETHING!! echo. print. printf.
fpassthru. (Maybe you want a header("Content-type: text/xml")
first).
echo "<xml>respo nse</xml>\n";
Note the complete absence of any reference to functions with the
substring "open" or "sock" and the complete absence of handles.
[color=blue]
>Or, more specifically, how do I establish a
>connection back to the requester so that I can send the response.[/color]
When you receive a telephone call, answer it, and the caller asks
a question, do you need to call him back to send answer? No, you
just *TALK*. It doesn't matter whether the caller is using a VOIP
switch or an old mechanical switchboard and asked the operator to
make the call for him. It doesn't matter whether the call goes
via a satellite. You just talk.
[color=blue]
>If I use fsockopen() to establish a connection to the requesting URL,[/color]
Do not establish a connection. You've got one established by the
other end. USE IT!
[color=blue]
>it appears that it would not be communicating with the same session. I
>also don't see a way to get a handle to the existing connection that
>was created by the requester.[/color]
on 11/27/2005 03:59 PM Zack said the following:[color=blue]
> My question deals with establishing a connection. It appears that
> establishing a new connection using fsockopen() would not connect me to
> the originator's session and I don't know how to re-use the existing
> connection.[/color]
You may want to try this HTTP Client class that can submit post
requests, collect and send back cookies (of your sessions) and most of
other operations to make it act like a real browser:
Comment