Chris Russo
Chris Russo

Reputation: 480

Parallel processes, ignore_user_abort and set_time_limit(0)

We're working on a system that uses ignore_user_abort() and set_time_limit(0) in one of the scripts.

We have to send one HTTP 1.1 packet to this script, with Jquery and then we have to resume and keep using other scripts inside the application.

But once the packet is sent, the session is somehow locked, and if you try to refresh or load any other script inside the domain, with the same browser, it won't load until the previous one finishes (and that might take more than 2 hours).

However it's possible to keep using the application from another browser, with the same username and password, which makes me think it's related to the session.

We need to prevent this or solve this somehow, to make this script run as a background processes without interfering with the functioning of the rest of the application.

Any idea how, or why this happens and how we could solve it?

The AJAX request looks like this:

<script>
$('#launch').click(function () {

//acomodamos la UI
$('#launch').hide();
$('#c_wait').slideUp();
$('#c_started').fadeIn("slow");

//send the request
$.get("modules/_map.php", { funcion: "launch", scan_id: "<?php echo $scan->id; ?>" } );                     
});
</script>

Upvotes: 1

Views: 294

Answers (1)

plasmid87
plasmid87

Reputation: 1471

I think you may be right - the problem could very well be session-related (your JavaScript doesn't indicate synchronous requests are being performed).

If you are running a long request that uses session information, you may find it beneficial to use the following code as a template for how you manage the session data:

// start the session
session_start();

// manipulate session data
// e.g.,
// $some_var = $_SESSION['some_var'];
// $_SESSION['some_var'] = 'something';

// flush any changes to the session and close
session_write_close();

// Start the long process here...

By using this approach you can manipulate the session before the long request starts, and then unlock it for subsequent requests using the same session.

Upvotes: 2

Related Questions