0

I am developing a Ticker support client in PHP with CodeIgniter, and I want to know if a user already open a ticket to hide this ticket from the list.

I know there is the solution of change a flag in database when the ticket is opened, then use :

 $(window).unload(function() {
    $.ajax({async:false ..... 
    /* change flag in database */
 });

But, what if the user's navigator is forcing to close ? Do I need a CRON task running to reset these flags ? Do you have some feedback for a complete solution ? Thanks.

3
  • 1
    "and I want to know if a user already open a ticket to hide this ticket from the list" this seems completely unrelated to the title. So what is that you want? Also what do you mean by "complete solution"? Complete code? Because if so, I think you came to the wrong place, we do not usually provide full code but suggestions on helping the user improve... not just copy. Commented Dec 19, 2012 at 9:09
  • Yes sorry for the title, this is hard to find the good words. I don't want a complete code, but some ideas for my problem. I want to know exactly if a ticket is opened by a user, and to know when the user close this ticket (by clicking on history back button for exemple, or if he close his navigator) Commented Dec 19, 2012 at 9:23
  • So you want to check if the user is no more on a specific page? Commented Dec 19, 2012 at 9:25

2 Answers 2

2

Since PHP runs only once per page load, the only way to check continuously if a user is still on the desired page you need Javascript + AJAX. How?

Every 1-5 minutes you update a specific field in the database using the timestamp of the last update (like you said) and in the PHP script you check that field in order to close or keep that ticket open.

By the way notice that this solution requires Javascript enabled so either you force the user to enable it (by blocking it otherwise) or you define that after few minutes (15-1hr) of no page loading you close the ticket.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a good solution, a AJAX call every 4 minutes on the ticket page to update a timestamp, and check if this timestamp was updated > 4 minutes in a PHP script, so the ticket was closed necessarily. I searched in the wrong direction, thanks !
0

I can suggest a couple of options.

  • using the ajax solution Jeffrey suggest.

    advantage: easy to implement, supported on all browsers

    disadvantage: not really live

  • using server sent events (similar to the ajax polling solution)

    advantage: less overhead

    disadvantage: not supported on IE & Android, not really live

  • websockets for a completely live solution. Make a connection, on connection lost or closed => release the ticket.

    advantage: live, least overhead

    disadvantage: not supported on <IE10 & Android, harder to implement on the server side.

However for the 'not supported' issues, there are fall-back techniques (modernizr)

1 Comment

I don't need a "fully live" solution, but thanks for WebSockets point, I did not think of this solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.