Good php, "nice" php

software development

#1

I am playing with a bit of php that is not being “nice”. This puppy takes too much CPU. Hammering a shared server for 20 seconds may not be appreciated by my neighbors.

Is there a way to make just a single script behave “nice”-ly? It is OK to have the user wait a few minutes for completion of the task.

Regards,
Rudy


#2

why is it taking so long?

What are you calling that involves such a lengthy execution stage?


#3

I do not have permission to post the source code, but it involves reprocessing graphics files.

Regards,
Rudy


#4

OK…

I would suggest that you use the script to collate any data required initially and then fork the scripts allowing the image processing to be done in the background.

You can achieve that by using exec() which you do have access to on dreamhost. Simple to implement the only difficulty will be passing all the data across.

exec(/usr/local/bin/php /home/USER/SITE.com/imageprocessingscript.php data1 data2 …datan> /dev/null &);

then in your imageprocessingscript.php you can access the variables sent via:

$_SERVER[‘argv’][1];
$_SERVER[‘argv’][2];

$_SERVER[‘argv’][n];

doing all this will allow the script to finish so the user is not waiting around and the the images will be processed when they can.

To avoid ‘annoying’ other users on yur shared server you can always have your own installation of php so your sites runs off that instead.

Finally are you using php4 or 5 5 has been shown to be faster (depending on your configuartion up to 10 times faster for the same functionality.


#5

Doh!
Thanks, I’ll try something along these lines:

<?php // verify $input is not "arbitrary code" // set $output exec(nice -n 19 /path/to/now_a_good_puppy.php>$output $input &); ?> Thinking one more thought on it, will the DH process watcher kill now_a_good_puppy.php as a “persistent process”?

Regards,
Rudy


#6

You can but try…

I would have thought though that the process will end with each request so fingers crossed you’ll be OK.