Jump to content

Statistics using AJAX and PHP


Harutyun

Recommended Posts

Hi.

 

I'm working on statistics application using php and mysql as back-end. The basic idea is to write any clicks' statistics to database when user clicks on any link on the site. My choice is synchronous  AJAX request to server using onbeforeunload event. I'm using synchronous request to be sure that browser sent request to the server before page is unloaded. With asynchronous request much requests do not get to the server especially with slow connections.

 

This approach works well so far, but as mysql database gets bigger, and php script more complicated, this will take more time to proceed request, which hangs browser for a little.

 

I just thought is there any way to send response to browser, close the connection (this normally happens after exit or die() in php script) and only after that continue script execution. So we will be sure that request is sent to server, and browser will not wait so long until php executes all the back-end logic. I've tried headers 200 OK and connection: closed, but no success so far.

 

Any ideas how to do it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.