Here is a really lite weight and untested theory.
open.php
<?php
session_start();
$_SESSION['fp'] = fsockopen($_GET['url'], 80, $errno, $errstr, 60);
// Do listen for 60 seconds, get data
while (!feof($_SESSION['fp'])) {
echo fgets($_SESSION['fp'], 128);
}
fclose($_SESSION['fp']);
unset($_SESSION['fp']);
?>
close.php
<?php
session_start();
if(isset($_SESSION['fp'])){
fclose($_SESSION['fp']);
unset($_SESSION['fp']);
}
?>
JavaScript
$(function(){
$("#go").click(function(){
$.get("open.php", { url: $("#url").val() }, function(results){
console.log(results);
});
});
$("#stop").click(function(){
$.get("close.php");
});
});
The idea here is that the File Pointer is stored in a session variable, so it can be called upon by other scripts. Since you didn't provide an example, I cannot say if this will work for you. I have never tested it since I've never wanted a script to close the connection prematurely. I've wanted to remain open until I got all my data and then close at EOF.
Alternatively, you can do something similar with the Process ID. Each PHP Script gets a PID when running. Discussed more here: How to kill a linux process using pid from php?