What if the user closes the browser while INSERT INTO MySQL?
What if the user closes the browser while INSERT INTO MySQL?
am 16.04.2010 11:39:07 von Antonio PHP
--00163630f40ffe54a8048457616d
Content-Type: text/plain; charset=ISO-8859-1
This maybe a newbie question.
Consider the following concept,
~/index.php
#1. Fetch data from an external webpage using PHP Curl;
#2. Preg_match/Prepare Data to INSERT from local MySQL; - this may take a
few secs
#3. While Loop { INSERT data (from #2) into local MySQL } - this may take
only mili secs.
Suppose this code is run by a random user (say, my website visitor), and
he/she closes the browser while the code was running. The real problem is
when the browser is closed while #3 is executing. Because only portion of
data is inserted, ~/index.php, and it doesn't know if it needs to visit the
site again (i.e. repeat from #1 -> over visiting the same webpage /
possibility of inaccurate data in local MySQL).
Has anyone come across with a similar problem? Do I need to use other
programming languages like C to execute the code from #2 in order not
to depend upon users' browser status?
Another general question : Is there a way to make sure all the data is
INSERTED in a while loop once it's triggered?
many thanks in advance,
- Anton
--00163630f40ffe54a8048457616d--
Re: What if the user closes the browser while INSERT INTO MySQL? (PHP/MySQL)
am 16.04.2010 11:44:42 von sql06
On Friday 16 April 2010 11:39, Antonio PHP wrote:
> This maybe a newbie question.
>
> Consider the following concept,
>
> ~/index.php
>
> #1. Fetch data from an external webpage using PHP Curl;
> #2. Preg_match/Prepare Data to INSERT from local MySQL; - this may take a
> few secs
> #3. While Loop { INSERT data (from #2) into local MySQL } - this may take
> only mili secs.
>
> Suppose this code is run by a random user (say, my website visitor), and
> he/she closes the browser while the code was running. The real problem is
> when the browser is closed while #3 is executing. Because only portion of
> data is inserted, ~/index.php, and it doesn't know if it needs to visit t=
he
> site again (i.e. repeat from #1 -> over visiting the same webpage /
> possibility of inaccurate data in local MySQL).
The server does not know if the browser is closed or not (or if the network=
=20
connection is losted). It will continue to execute the code until finnished.
=2D-=20
J=F8rn Dahl-Stamnes
homepage: http://www.dahl-stamnes.net/dahls/
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: What if the user closes the browser while INSERT INTO MySQL?(PHP/MySQL)
am 16.04.2010 13:31:16 von nwood
> > Consider the following concept,
> >
> > ~/index.php
> >
> > #1. Fetch data from an external webpage using PHP Curl;
> > #2. Preg_match/Prepare Data to INSERT from local MySQL; - this may take a
> > few secs
> > #3. While Loop { INSERT data (from #2) into local MySQL } - this may take
> > only mili secs.
> >
> > Suppose this code is run by a random user (say, my website visitor), and
> > he/she closes the browser while the code was running. The real problem is
> > when the browser is closed while #3 is executing.
> The server does not know if the browser is closed or not (or if the network
> connection is losted). It will continue to execute the code until finnished.
I'm not sure that's exactly correct. "The default behaviour is however
for your script to be aborted when the remote client disconnects."
http://www.php.net/manual/en/features.connection-handling.ph p
You can certainly set a script not to terminate if the user aborts
during the page request using ignore_user_abort() or a php.ini setting.
HTH
Nigel
P.S. Sorry to the other list users for a PHP oriented discussion.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: What if the user closes the browser while INSERT INTO MySQL?
am 16.04.2010 13:43:47 von Geert-Jan Brits
--001485f1d7c8cdb5fe0484591fce
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
As a side-note: letting a random user (such as your website visitor) wait
for a couple of seconds is usually not good practice, unless you have a ver=
y
good incentive for them to do so.
2010/4/16 J=F8rn Dahl-Stamnes
> On Friday 16 April 2010 11:39, Antonio PHP wrote:
> > This maybe a newbie question.
> >
> > Consider the following concept,
> >
> > ~/index.php
> >
> > #1. Fetch data from an external webpage using PHP Curl;
> > #2. Preg_match/Prepare Data to INSERT from local MySQL; - this may take=
a
> > few secs
> > #3. While Loop { INSERT data (from #2) into local MySQL } - this may ta=
ke
> > only mili secs.
> >
> > Suppose this code is run by a random user (say, my website visitor), an=
d
> > he/she closes the browser while the code was running. The real problem =
is
> > when the browser is closed while #3 is executing. Because only portion =
of
> > data is inserted, ~/index.php, and it doesn't know if it needs to visit
> the
> > site again (i.e. repeat from #1 -> over visiting the same webpage /
> > possibility of inaccurate data in local MySQL).
>
> The server does not know if the browser is closed or not (or if the netwo=
rk
> connection is losted). It will continue to execute the code until
> finnished.
>
> --
> J=F8rn Dahl-Stamnes
> homepage: http://www.dahl-stamnes.net/dahls/
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgbrits@gmail.com
>
>
--001485f1d7c8cdb5fe0484591fce--
Re: What if the user closes the browser while INSERT INTOMySQL? (PHP/MySQL)
am 16.04.2010 14:01:53 von Carsten Pedersen
http://php.net/manual/en/function.ignore-user-abort.php
/ Carsten
On Fri, 16 Apr 2010 18:39:07 +0900, Antonio PHP
wrote:
> This maybe a newbie question.
>
> Consider the following concept,
>
> ~/index.php
>
> #1. Fetch data from an external webpage using PHP Curl;
> #2. Preg_match/Prepare Data to INSERT from local MySQL; - this may take
a
> few secs
> #3. While Loop { INSERT data (from #2) into local MySQL } - this may
take
> only mili secs.
>
> Suppose this code is run by a random user (say, my website visitor), and
> he/she closes the browser while the code was running. The real problem
is
> when the browser is closed while #3 is executing. Because only portion
of
> data is inserted, ~/index.php, and it doesn't know if it needs to visit
the
> site again (i.e. repeat from #1 -> over visiting the same webpage /
> possibility of inaccurate data in local MySQL).
>
> Has anyone come across with a similar problem? Do I need to use other
> programming languages like C to execute the code from #2 in order not
> to depend upon users' browser status?
>
> Another general question : Is there a way to make sure all the data is
> INSERTED in a while loop once it's triggered?
>
> many thanks in advance,
>
> - Anton
>
>
> !DSPAM:451,4bc835a5518712071889376!
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: What if the user closes the browser while INSERT INTOMySQL? (PHP/MySQL)
am 16.04.2010 14:33:23 von Carsten Pedersen
On Fri, 16 Apr 2010 11:44:42 +0200, Jørn Dahl-Stamnes
wrote:
> The server does not know if the browser is closed or not (or if the
> network
> connection is losted). It will continue to execute the code until
> finnished.
Not quite true. If it decides to flush its output buffer and notices that
there's no-one around to receive the output, the process may well be
terminated.
As long as you do not echo(), print() or flush() to a closed connection,
you're probably going to be fine.
/ Carsten
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: What if the user closes the browser while INSERT INTO MySQL?
am 17.04.2010 17:40:06 von Antonio PHP
--0016364ec8a8cb2ab20484708a3a
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Well... just summarizing my thread here.
I tested this today.
As Carsten mentioned...
Without the function 'ignore_user_abort(true);', when the browser is
closed the script will stop at some point (if there's output ('echo etc') o=
f
certain number (1,000s) of characters remaining.).
Many Thanks to Carsten!!
On Fri, Apr 16, 2010 at 9:33 PM, Carsten Pedersen wrot=
e:
>
> On Fri, 16 Apr 2010 11:44:42 +0200, J=F8rn Dahl-Stamnes
> wrote:
>
> > The server does not know if the browser is closed or not (or if the
> > network
> > connection is losted). It will continue to execute the code until
> > finnished.
>
> Not quite true. If it decides to flush its output buffer and notices that
> there's no-one around to receive the output, the process may well be
> terminated.
>
> As long as you do not echo(), print() or flush() to a closed connection,
> you're probably going to be fine.
>
> / Carsten
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=3Dphp.antonio@gmail.com
>
>
--0016364ec8a8cb2ab20484708a3a--
Re: What if the user closes the browser while INSERT INTO MySQL?
am 19.04.2010 14:36:45 von Johan De Meersman
--0016e64ccc36bdb1870484963685
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Apr 16, 2010 at 1:31 PM, Nigel Wood wrote:
> P.S. Sorry to the other list users for a PHP oriented discussion.
>
Get a room, you two :-)
--
Bier met grenadyn
Is als mosterd by den wyn
Sy die't drinkt, is eene kwezel
Hy die't drinkt, is ras een ezel
--0016e64ccc36bdb1870484963685--
Re: What if the user closes the browser while INSERT INTO MySQL?
am 19.04.2010 16:13:29 von Michael Dykman
On this level, it's more of an apache/web-server-in-general issue.
There are 2 connections to be considered here: the connection between
the browser and the web server and the connection between the
webserver (running PHP for example) and the database and they have
very different behaviours.
If the connection is lost between the web server and the database, the
connection will abort and any pending uncommited operations are rolled
back.
If the connection is lost between the browser and the webserver, that
is another matter. Generally, webservers do not notify server-side
applications of that connection abort so that code will continue to
completion with it's output being lost to the ether. As the
application is not notified of the disconnect; the database server
never hears about it and continues to do as requested.
So: connection lost between browser and webserver affects nothing
except the browser... Should the server-side application itself
abort, uncommited changes will be lost.
On Mon, Apr 19, 2010 at 8:36 AM, Johan De Meersman wrote:
> On Fri, Apr 16, 2010 at 1:31 PM, Nigel Wood wrote:
>
>> P.S. Sorry to the other list users for a PHP oriented discussion.
>>
>
> Get a room, you two :-)
>
> --
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel
>
--
- michael dykman
- mdykman@gmail.com
May the Source be with you.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org