Jump to content

Php / https connection, detecting protocol error


benwa

Recommended Posts

Hi,

 

I have the following situation:

- I have a client that is sending a HTTPS request to a php webpage on my server (with data in GET parameters)

- On this webpage I execute some scripts. These scripts require some database lookups and can sometimes take a while.

- If all code has succesfully finished, the webpage shows "OK" and if an error happened the webpage shows "ERROR"

 

It is very important that both the client and me can detect if something is going wrong in this process.  Because the scripts on my server can only be executed once for each request.

 

Now, the client retry's the request if he doesn't get the "OK" and if he is unable to open the webpage and if a protocol error or timeout happens.

 

This gives us the certainty that all request are succesfully received by my script.

 

The problem is however, that if the client receives a "protocol error", I see that the script on my server was still executed.  The client however thinks there was an error, and retry's a bit later.  This results is a dubbel executed script.  And I don't want this to happen.

 

So the question is: how can I detect in my php script if the connection is still active and the client is still there?  If the connection if not alive anymore and the client won't be able to detect the "OK", the script needs to reverse his action, so that the action won't be executed twice.

 

hope someone can help me with this!

  • 2 weeks later...

You can't exactly do this. PHP scripts do not contain tunnels with an open connection. They send a request, the data gets generated and sent back, whether the recipient is still there or not.

 

The closest thing you could try doing is pinging the client at the end of the script and seeing if you get a response, but even then it wouldn't tell you whether or not the client got all the data, just that the client still exists.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.