How to find multiples of 1000 for comparison ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    How to find multiples of 1000 for comparison ?

    Hi,
    I want to slow down my script so that
    mySQL server can keep up.

    I am counting the row numbers with $cnt
    so after $cnt++; I want to add:

    if ($cnt xxx ) sleep(2);

    now xxx needs to be "any multiple of 1000" but I am
    not sure how to code that.

    As I am processing upto 30,000 records, I can not write out

    if ($cnt == 1000 || $cnt == 2000 || $cnt == 3000 || $cnt == 4000 || etc etc up to 30,000)

    Does anyone know how I can do this ?

    Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    use the modulo operator (%).

    Comment

    • rudiedirkx
      New Member
      • Jan 2010
      • 7

      #3
      Eeeh:
      I want to slow down my script so that mySQL server can keep up.
      I'm pretty sure it doesn't work that way :) PHP only goes as fast as MySQL can handle queries. If you MySQL queries are "too slow for PHP", your PHP script entirely will be slow. If your MySQL is very, very fast, PHP will be as slow as it's PHP code.

      When sleep() is used, the entire script/program/application holds/sleeps/does nothing. MySQL doesn't gain by it. Use sleep only if you really want to do nothing (for example a socket timer, or an ajax chat timer, or something)

      Comment

      Working...