Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using php sleep() function a good idea to keep CPU load down with heavy script?

Tags:

php

sleep

I have a "generate website" command, that parses through all the tables to republish an entire website into fixed html pages. That's a heavy process, at least on my local machine (the CPU rises up). On the production server it does not seem to be a problem so far but i would like to keep it future proof. Therefore i'm considering using the php sleep() function between each step of the heavy script so that the server has time to "catch its breath" between the heavy steps.

Is that a good idea or will it be useless?

like image 560
pixeline Avatar asked Mar 18 '09 17:03

pixeline


2 Answers

If you're running php5, and it's being used in CGI (rather than mod_php) mode, then you could consider using proc_nice instead.

This could allow the "generate website" command to use as much CPU as it wants while no-one else is trying to use the site.

like image 143
Alnitak Avatar answered Oct 31 '22 12:10

Alnitak


I would simply not do this on the Production Server, the steps I have followed before:

  1. Rent a low cost PHP server - or get a proper Dev server setup that replicates the production

  2. All Dynamic files are copied to DEV - they dont even need to be on the production

  3. Run the HTMLizer script - no sleep just burn it out

  4. Validate the ouput and then RSYNC this to the live server - backing up the live directory as you do it so you can safely fall back

Anyway since Caching / Memcaching came up to speed I havent had to do this at all - use Zend Framework and Zend Cache and you basically have a dynamic equivalent to what you need to do automatically.

like image 45
Ian Warner Avatar answered Oct 31 '22 12:10

Ian Warner