PHP/MySQL Process CPU Limit

Discussion in 'PHP' started by sv4rog, Jul 6, 2007.

  1. #1
    Hi, i am developing a PHP5/MySQL website and testing it on my local machine, on an Apache server. And I have a problem.
    I have written a PHP script that does a lot of computing and MySQL queries. I start it from a link on one of the pages on the site and when it's complete, and when it's done it writes in the output a sort of a "OK, DONE" statement on the next page.
    This script has a lot of loops and can take up to 15 minutes to complete. The problem is that, while it is running, it takes up all of my CPU power, and I can't browse/do other stuff on the site until it's over.

    It's definitely CPU, not memory - i tried to change memory_limit but it doesn't help.

    Is there any way that I can limit the amount of CPU available to a single script???

    (I don't mind if the script takes longer to complete, as long as I can do other stuff on the page comfortably while it is running.)
     
    sv4rog, Jul 6, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What sort of script is it running.

    I have never seen anything take that long to compute, and I have seen some massive looping scripts.

    You also might look into using sleep() and breaking up the script after a certain number of loops.

    Also, if there are things that will make the script use less load, I would definitely work on optimizing it as much as possible.
     
    jestep, Jul 6, 2007 IP
  3. sv4rog

    sv4rog Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well, basically, the script generates a lot of random data and puts it the database (for example, like generating random names, and more).
    Since I'm pretty much a newbie, i admit that the script could probably be optimized much better.
    But thanks, I will try with sleep().
     
    sv4rog, Jul 7, 2007 IP