Jump to content

Archived

This topic is now archived and is closed to further replies.

holowugz

Image size checking script

Recommended Posts

Hi i wrote a script that would go through all of the members on my forums and check there signature image sizes:
now it works great for one person but it is taking an extremely long time to go through the entire thing, and i was wondering if i had coded something wrong or someone knows a way to optomise the script:

here is an example signature from the db:
[code]
[IMG]http://www.sighost.us/members/lalias/tyler1z.jpg[/IMG]
[IMG]http://www.ufdf.com/sigs/officially-gay.png[/IMG][img]http://img97.imageshack.us/img97/7767/clanbitch9ns.png[/img][img]http://www.ufdf.com/sigs/ufdf-member.png[/img][img]http://img74.imageshack.us/img74/5104/clanslut8fk.png[/img][img]http://www.ufdf.com/sigs/moocat-lover.png[/img]
[img]http://www.ufdf.com/sigs/sci-fi-freak.png[/img][img]http://www.ufdf.com/sigs/luke's-bitch.png[/img][img]http://www.ufdf.com/sigs/-canada.png[/img][img]http://www.ufdf.com/sigs/-gaypride.png[/img]
[/code]

[code]
<?PHP
set_time_limit(0);
require_once('Connections/connPASSWORD.php');
mysql_select_db($database_connPASSWORD, $connPASSWORD);
$query_RsSig = "SELECT u.username, t.signature FROM vb3_usertextfield t, vb3_user u WHERE (t.userid = u.userid) AND (t.signature <> '') AND (u.usergroupid = 26)";
$RsSig = mysql_query($query_RsSig, $connPASSWORD) or die(mysql_error());
$row_RsSig = mysql_fetch_assoc($RsSig);
$totalRows_RsSig = mysql_num_rows($RsSig);
//set variables
$imageLine = 1;
$height = 0;
$width = 0;
$maxheight = 500;
$maxwidth = 600;
//create an array called data where the assosiative name is the persons username, and set the value to the signature value
do {
$data[$row_RsSig['username']] = $row_RsSig['signature'];
} while ($row_RsSig = mysql_fetch_assoc($RsSig));
//valuedata is username cheesedata is the signature
foreach ($data as $valuedata => $cheesedata){
//create an array called sigdata and and split it line by line.
$sigdata = explode("\r\n",$cheesedata);
//create a loop for every single line of the array
foreach ($sigdata as $value => $cheese){
//check if the data matches the regex and if it does put the link to the image in the matches array.
preg_match_all('/\\[IMG\\](.+?)\\[\/IMG]/i', $cheese, $match);

//get the number of images in the current matches array
$numImages = count($match[1]);
if($numImages != 0){
foreach ($match[1] as $value1 => $cheese1){
$imagedata = getimagesize($cheese1);

$height1 = $imagedata[1];

if($height1 > $height){
$height = $height1;
}

$width = $width + $imagedata[0];

$siginfo["Line$imageLine"]['width'] = $width;
$siginfo["Line$imageLine"]['height'] = $height;
$width = 0;
$height1 = 0;
$height = 0;
}
$finalInfo['height'] = $finalInfo['height'] + $siginfo["Line$imageLine"]['height'];
if($siginfo["Line$imageLine"]['width'] > $finalInfo['width']){
$finalInfo['width'] = $siginfo["Line$imageLine"]['width'];
}
}
//reset variables

$imageLine ++;
$sigdata = array();
$siginfo = array();
}
if($finalInfo['height'] > $maxheight or $finalInfo['width'] > $maxwidth){
echo $valuedata ;
echo "<br/>";
var_dump($finalInfo);
echo "<br/>";
}
$finalInfo = array();
//end of main foreach loop
}
mysql_free_result($RsSig);
?>

[/code]

Share this post


Link to post
Share on other sites
There is probobly a way to optamise it, but, heck, going throgh EVERY user in a databse (even a few hundred) is an intesive task. You could always ignore user abort and not worry how long it takes, if you only intend to run it every once in a while.
http://php.net/manual/en/function.ignore-user-abort.php

Share this post


Link to post
Share on other sites
yeah i know, i mean considering that some users have like 20 images in their sig it is a nightmare for me.
so i am thinking i was going to run it as a cron job and make it generate a text file with the names of people who are over limit or something?

But do you know any other way to optomise it?

Share this post


Link to post
Share on other sites
Personally, i would run it once, and modify the code that allows them to edit their signatures to check for image size (thus eliminating the need for an intensive cron)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.