[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php mysql

Posted on 2012-09-12
6
Medium Priority
?
436 Views
Last Modified: 2012-09-13
dear experts ..
i am using a cronjob to execute a script every period of time ..

think of the database as follows ..

database name is ( abc )
table 1

and i have around 1000 cronjobs each of which is access the database abc and the table to read and ulter some data ..
knowing that some of the cronjobs are being executed in parrallel
1- the question is : executing these scripts in parrallel targeting the same database same table would affect any thing ?

2- what about accessing same database in parrallel but with different tables ?
0
Comment
Question by:mokatell
6 Comments
 
LVL 4

Expert Comment

by:GBigA
ID: 38390981
It depends on the type of table you are accessing.

"MySQL uses table-level locking for MyISAM, MEMORY and MERGE tables, page-level locking for BDB tables, and row-level locking for InnoDB tables."

This is found here: http://dev.mysql.com/doc/refman/5.0/en/internal-locking.html

2- if you are accessing different tables, there wont be a problem with locking.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38391017
Think of it this way.

If you have a website accessing a database and you have many people accessing the site simultaneously - how is that different from what you are describing?
0
 

Author Comment

by:mokatell
ID: 38391021
the engine type is ennoDB ..
any suggestions ..
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:mokatell
ID: 38391039
@julian ..
yes you are right , it makes no difference ..
but u didnt suggestion any kind of solution ..
... ummmmmmmmmm wierd ..
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38391192
I didn't suggest a solution because unless you are doing something that require synchronisation there should be no issues - my point was if that is the standard modus operandi of most sites which for the most part function without issues then there should be no issue with what you are doing.

The majority of websites I would think operate in a read-only mode i.e. the pull data from a database. In the case of ones that write back (shopping carts) there is little to no overlap i.e. when you add something to your own cart you are accessing a different record from the other users of the site.

The only problem you could have is if you are updating the database and your cron jobs could end up accessing the same record for writing in which case you can look at the synchronisation functions (table and record locks) which will allow your scripts to run without hurting each other.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38391746
MySQL returns INSERT identifiers (auto-increment keys) on a per connection basis, so if each script makes its own connection to the data base, your INSERT ids will be correct.  However if you are making updates to the tables, especially updates that affect more than one table, you should use LOCK TABLES to prevent what is called "race conditions" and works as follows...

Script #1 SELECTs data from a row and begins preparing an update to the row.
Script #2 SELECTs data from the same row and begins preparing an update.  Script #2 finishes its UPDATE before Script #1.
Script #1 UPDATEs the row, overwriting the information from Script #2.

Does that help? ~Ray
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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