php mysql

Posted on 2012-09-12
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 ?
Question by:mokatell
    LVL 4

    Expert Comment

    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:

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

    Expert Comment

    by:Julian Hansen
    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?

    Author Comment

    the engine type is ennoDB ..
    any suggestions ..

    Author Comment

    @julian ..
    yes you are right , it makes no difference ..
    but u didnt suggestion any kind of solution ..
    ... ummmmmmmmmm wierd ..
    LVL 50

    Expert Comment

    by:Julian Hansen
    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.
    LVL 107

    Accepted Solution

    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

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now