# Stop AJAX Request After Time Limit

**URL:** <https://forum.kirupa.com/t/stop-ajax-request-after-time-limit/309198>\
**Category:** programming\
**Created:** [May 9, 2010, 3:48pm UTC](https://forum.kirupa.com/t/stop-ajax-request-after-time-limit/309198 "2010-05-09T15:48:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![riveroaks](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@riveroaks](https://forum.kirupa.com/u/riveroaks)\
**Post date:** [May 9, 2010, 3:48pm UTC](https://forum.kirupa.com/t/stop-ajax-request-after-time-limit/309198/1 "2010-05-09T15:48:18Z")

</div>

I’ve got an AJAX request going to a PHP proxy which uses a 3rd party service to grab some data I need. The speed of this 3rd party system is variable, and I would like to cancel the request after 5 seconds if it hasn’t gone through. Does anyone know how to do this?

I could run a timer in JavaScript - but even when I realize 5 seconds have gone by, I don’t know how to actually cancel that AJAX request. The request will eventually come back and run the JavaScript callback function which will not be good.

I tried using PHP’s set\_time\_limit, but for some reason its not working. In fact, testing with a sleep() function, I found that I have to exceed 60 seconds to hit the PHP time limit.

I also thought about just running in a tight loop and checking the time. However, to make this work I would need to be running some kind of multi-threaded system. I don’t even know if PHP supports threading.

So any help with this problem would be appreciated.

Thanks.
