Solved

Delayed transactions INSERT/UPDATE with PHP

Posted on 2012-04-05
10
310 Views
Last Modified: 2012-06-27
I have a PHP script on our internet server that sends either an INSERT or UPDATE SQL statement to a table in a small local database. I've tried this with mySQL and Postgress but get exactly the same weird effect.

Firstly, my PC based app sends the data to the PHP script which loads it into the table every 10 seconds in a sequence of about 50 transactions. I then close the app.

In the following hour new records are magically inserted or updated even though nothing is calling the PHP script.

I can only assume that PHP transactions that were made have somehow been delayed by up to an hour coming in randomly, out of sequence, every few minutes and changing the table.

Any help with understanding what's going on and how to solve it much appreciated.
0
Comment
Question by:ChrisJonesLycos
10 Comments
 
LVL 20

Expert Comment

by:virmaior
ID: 37814866
It would take some additional details to figure out what is going wrong here.

Specifically, I need more detail on what is meant here: "my PC based app sends the data to the PHP script which loads it into the table every 10 seconds in a sequence of about 50 transactions. I then close the app. "

(1) It's not clear to me how your "PC based app" sends data.
(2) The PHP on the server runs the SQL queries? [i.e. not your PC based app]
(3) What starts the PC-based app?

With just what you've stated, I can say the following:
(1) Neither PHP nor MySQL randomly do things out of order or wait for hours.
(2) This means either (a) something is taking a significant amount of time [like transferring large data or extremely complex processing is causing some entries to appear later] or (b) something else is writing to the database or (c) there's an out of order execution happening where it is not that data happens late so much as data and processing cross awkwardly.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37815138
> .. new records ..
are these records with the same data as already added?

I assume that your clients (browser) sends the same request again and again, for example if a browser is restarted
0
 

Author Comment

by:ChrisJonesLycos
ID: 37815216
I've been doing more testing in the meantime so I'll put the results here and hopefully answer some of the requests for more info above. To clarify one point before I begin, the PC based app sends the data to the php script via a .php?QUERY_STRING. The data it's sending is only 4 fields with minimal data.

The sequence I've now followed in testing is:

1. I have an empty table. Via the php script I INSERT one record:
UserID: int; DateTime stamp; Duration: int; DocumentName: varchar(100)

2. Every 10 seconds after that an UPDATE query, sent via the php script, updates the Duration field by 10 seconds. It does this 30 times. After each UPDATE I do a SELECT query on that record and the database reports that the information updated is in fact there.

3. I then close any app or anything else that can talk to the database. I do a DELETE FROM myTable. To double check it's empty I do a SELECT * FROM myTable and it reports no rows.

4. I then at 2 or 3 minute intervals over the next hour do a SELECT * FROM myTable. Each time I do a select, random values from the sequence of 30 updates appear. There is no particular order or sequence to them. Finally, they settle down to a value that does not change. It's usually somewhere in the middle of the sequence.

I think from this I can surmise that it is in fact not the PHP scripts being delayed: an update on an empty table would not produce a record. It seems more like inexplicable behaviour of the database. However, what I cannot fathom is that I have set this up on both mySQL and Postgres and get exactly the same behaviour. The server is not ours, we rent the space on it so I am a bit vague about the underlying setup.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 20

Expert Comment

by:virmaior
ID: 37816422
How are you doing the later selects (i.e. your step 4)?

i.e. are you using an ODBC connector, MS Access, phpmyadmin, or some other means?

I can imagine either an issue with cached DB results due to a faulty connector OR a system where in fact they are using a large number of slave copies of the database that are delayed in getting the updates.
0
 

Author Comment

by:ChrisJonesLycos
ID: 37816829
The step 4 SELECTs are done using myPHPAdmin or myPGAdmin in either case.

Whatever ends up there after about an hour becomes the permanent state of the table, that's to say, even following the DELETE FROM an hour later there will be a permanent record in the table that then doesn't change.
0
 
LVL 22

Expert Comment

by:earth man2
ID: 37819859
when does the commit happen ?
0
 
LVL 20

Expert Comment

by:virmaior
ID: 37820016
if you use SHOW CONNECTION  in phpMyAdmin, are there any connections open at the time?
0
 

Author Comment

by:ChrisJonesLycos
ID: 37822638
I've turned off AUTOCOMMIT and I do an explicit commit in the php directly following the INSERT/UPDATE.

If I do SHOW STATUS in phpMyAdmin and check Threads_connected it says 1 both during the process and following it.
0
 

Accepted Solution

by:
ChrisJonesLycos earned 0 total points
ID: 37881548
This bug is easily duplicatable and it's obviously some horribly bodged coding somewhere in the php interpreter.

I've finally resolved it simply by using POST rather than GET as the method for transferring data to the php script.

I'm canceling my subscription to this site as questions like this never get answered.
0
 

Author Closing Comment

by:ChrisJonesLycos
ID: 37905321
.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question