Jquery's Ajax and killing SQL process on PHP -
so have script import .csv file, line line using "insert query" database.
i want user able stop script anytime.
here's ajax call :
postselect = $.post('addcsvtodatabase.php');
- first try :
here's initial handler stop script :
$('#input').click(function(){ postselect.abort(); })
i noticed abort() method did stop script, data still being inserted database
- second try :
from .php script run on initial ajax call (addcsvtodatabase.php), save process id of sql query :
$idconnexion = $connexion->query('select connction_id()')->fetch(pdo::fetch_assoc); $idconnexion = $idconnexion["connection_id()"]; $_session['idconnexion'] = $idconnexion;
then, make ajax call abortsql.php script grab process id , try kill :
$requete = "kill ".$_session['idconnexion']; $connexion->query($requete);
here's input handler looks :
$('#input').click(function(){ postselect.abort(); $.post( "abordsql.php"); })
the thing is, noticed when try abort import, abortsql.php in "loading" mode , fire when initial ajax call finished, kill process when process finished, not usefull.
i tried kill process manually on phpmyadmin (i'm getting same process id script , phpmyadmin, no issue there), , works, stop importing data database.
how can run abordsql.php script without waiting initial ajax call end ?
thanks !
after $_session['idconnexion'] = $idconnexion;
, add:
session_write_close();
the session file open , locked, abort script can't start session.
Comments
Post a Comment