I'm on my knees begging (PHP stats related)

I'm actually trying to move away from databases. All of the individual data is stored in a set of cmp files (one for each day) which are automatically updated every hour. The files for the last couple of weeks are 100% compatible with SETITeam and once I've got around to converting the older ones I'll be making them all accessible for download.

The team table still uses a database although at some point I plan on converting that to use the same format of file to make it easier for me to reuse code accross the two sets of stats.

Also the 'older' sigs (Mine, walsherz and a few others) still use a database for storage of settings which I will probably shut down once the new script is fully up and running.
 
Understood, what I meant was that you already dl the data for the entire team etc on a regular basis so that wouldn't need to be part of your script for the sig generator, or well thats what I would do, no point having the data in more than one place if its not necessary.
 
Originally posted by kaiowas
I'm actually trying to move away from databases.
Any particular reason for that? I would have thought that you could get at individual user stats much quicker using a simple database than you could by searching lots of individual files (although keeping the CMP files as well isn't a bad idea).
 
Originally posted by Mark G
I would have thought that you could get at individual user stats much quicker using a simple database than you could by searching lots of individual files

You'd think so wouldn't you?

Have you compared the loading time of the team table to the other stats?
 
Originally posted by kaiowas
Have you compared the loading time of the team table to the other stats?
Yes, I have, but I don't know what the database structure is, or what's stored, so I can't comment on why it's that slow.

From what I've seen of MySQL performance (we use it at work), it's pretty quick, so I'm not sure why you're having performance problems with it.
 
Originally posted by Mark G
Yes, I have, but I don't know what the database structure is, or what's stored, so I can't comment on why it's that slow.

From what I've seen of MySQL performance (we use it at work), it's pretty quick, so I'm not sure why you're having performance problems with it.

tbh honest I think it's slow because plusnet run MySQL on a separate server which isn't really up to the job.

Also by moving the scripts away from a database it allows for easier portability in the future if it becomes necessary to move the scripts to another host for any reason.
 
Hmm. I have done a copy and paste of kaiowas's script (from the post by mark) and it ain't working. Can anyone point me out to what is wrong? This is what I get,

Warning: fgets(): supplied argument is not a valid File-Handle resource in /mnt/web_b/d28/s24/a000ioo2/www/php/sig.php on line 64

Warning: fclose(): supplied argument is not a valid File-Handle resource in /mnt/web_b/d28/s24/a000ioo2/www/php/sig.php on line 65

Fatal error: Call to undefined function: imagettfbbox() in /mnt/web_b/d28/s24/a000ioo2/www/php/sig.php on line 72

You can study the script at http://www.alexander-price.com/php/sig.php

Btw, this is just a trial run. I'll be putting my own message on and everything later, so I haven't customised the font color or message yet. I just wanna get it working before I start to play around with it.

Thanks
 
Erm dont think you can do it with windows browser.
Download CuteFTP, Smart FTP etc... and logon to you FTP select the directory and right click it you should have the option to chmod it. Set it to 777.
 
I'm pretty sure you can't do it with Windows browser-based FTP, but you can do it with SmartFTP or the windows command-line FTP.

For Windows command-line, the command you need is:
Code:
quote site chmod 777 <directory>
Using the appropriate directory name of course.
 
Originally posted by TrUz
Check you paths, they must be absolute.

I have this;

//Setup Variables For Webspace - Must be absolute paths
$LocalFile="/www/php/data/WUTotal.dat";
$FontFile="/www/php/data/t.TTF";

I believe thats right :confused:

If I go to ftp://alexanderprice.netfirms.com I see three folders. If i click on the www folder, then the php folder, i can see the data folder so surely that means the paths are correct?

If it helps, my php test file is located here -

http://www.alexander-price.com/php/test.php
 
Code:
<?php

//Code for overlaying SETI stats over a JPEG or PNG image
//By Phil Cutler (kaiowas) of Team OcUK Oct 2002
//Revised by Mark Gray Apr 2003
//Visit the OcUK team forum: [url]http://forums.overclockers.co.uk/forumdisplay.php?&forumid=39[/url]
//Uses a local file to cache the users total and reduce bandwidth hit on Berkeley

//Setup Variables For Sig
   $UserEmail="[email protected]";
   $PreText="Team OcUK - Get WU's Or Die Tryin'";
   $PostText="WU's owned";
   $TextRed=251;
   $TextGreen=251;
   $TextBlue=251; 
   $FontSize=12;
   $TextX=350;
   $TextY=12;
   $ImageURL="http://alexanderprice.netfirms.com/images/wasc_sig.jpg";
   $UpdatePeriod=900; //Maximum frequency in seconds at which the script will poll Berkeley 

//Setup Variables For Webspace - Must be absolute paths
   $LocalFile="/www/php/data/WUTotal.dat";
   $FontFile="/www/php/data/t.TTF"; 


   if(!file_exists($LocalFile) or !FileMTime($LocalFile) or time()-FileMTime($LocalFile)>$UpdatePeriod)
   {

    //Get Total Number Of WUs from personal stats page at Berkeley
    $fp =@fopen ("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=" . $UserEmail . "&cmd=user_stats_new", "r");
    if ($fp)
    {
     while (!feof($fp))
     {
      $WebPage.=fgets($fp,200);
     }
     fclose($fp);

     if (strpos($WebPage,"No user with that name was found")==0)
     {
      $TotalStart=strpos($WebPage,"Results Received");
      $StartPos=strpos($WebPage,"<td>",$TotalStart)+4;
      $EndPos=strpos($WebPage,"</td>",$StartPos);
       $WUs=ltrim(rtrim(substr($WebPage,$StartPos,$EndPos
-$StartPos)));
     }
     else
     { 
      $WUs="User not found."; 
     }

     //Update Local File With Total
     $Output = fopen ($LocalFile, "a"); 
     ftruncate ($Output, 0);
     fseek($Output,0);
     fwrite($Output, $WUs);
     fclose($Output);
    }
   }

   //Read Total from Local File
   $Local=@fopen ($LocalFile, "r");
   $WUs=fgets($Local,200);
   fclose($Local);


   //Build Text String
   $Text=$PreText . "\r\n" . $WUs . " " . $PostText;

   //Create Image
   $size = ImageTTFBbox ($FontSize, 0, $FontFile , $Text);

   $im_x=abs($size[4]-$size[0]);
   $im_y=abs($size[5]-$size[1]);

   if (substr($ImageURL,strlen($ImageURL)-3,3)=="jpg")
   {
    //Create a Sig image based on a JPEG
    Header("Content-type: image/jpeg");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromJPEG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImageJpeg ($im);
    ImageDestroy ($im);
   }
   elseif (substr($ImageURL,strlen($ImageURL)-3,3)=="png")
   {
    //Create a Sig image based on a PNG
    Header("Content-type: image/png");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromPNG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImagePNG ($im);
    ImageDestroy ($im);
   }
?>
 
Thats wrong me old cup cake. you wont.


Code:
<?php

//Code for overlaying SETI stats over a JPEG or PNG image
//By Phil Cutler (kaiowas) of Team OcUK Oct 2002
//Revised by Mark Gray Apr 2003
//Visit the OcUK team forum: [url]http://forums.overclockers.co.uk/fo...php?&forumid=39[/url]
//Uses a local file to cache the users total and reduce bandwidth hit on Berkeley

//Setup Variables For Sig
   $UserEmail="[email protected]";
   $PreText="Team OcUK - Get WU's Or Die Tryin'";
   $PostText="WU's owned";
   $TextRed=251;
   $TextGreen=251;
   $TextBlue=251; 
   $FontSize=12;
   $TextX=350;
   $TextY=12;
   $ImageURL="http://alexanderprice.netfirms.com/images/wasc_sig.jpg";
   $UpdatePeriod=900; //Maximum frequency in seconds at which the script will poll Berkeley 

//Setup Variables For Webspace - Must be absolute paths
   $LocalFile="/mnt/web_b/d28/s24/a000ioo2/www/php/data/WUTotal.dat";
   $FontFile="/mnt/web_b/d28/s24/a000ioo2/www/php/data/t.TTF"; 


   if(!file_exists($LocalFile) or !FileMTime($LocalFile) or time()-FileMTime($LocalFile)>$UpdatePeriod)
   {

    //Get Total Number Of WUs from personal stats page at Berkeley
    $fp =@fopen ("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=" . $UserEmail . "&cmd=user_stats_new", "r");
    if ($fp)
    {
     while (!feof($fp))
     {
      $WebPage.=fgets($fp,200);
     }
     fclose($fp);

     if (strpos($WebPage,"No user with that name was found")==0)
     {
      $TotalStart=strpos($WebPage,"Results Received");
      $StartPos=strpos($WebPage,"<td>",$TotalStart)+4;
      $EndPos=strpos($WebPage,"</td>",$StartPos);
        $WUs=ltrim(rtrim(substr($WebPage,$StartPos,$EndPos

-$StartPos)));
     }
     else
     { 
      $WUs="User not found."; 
     }

     //Update Local File With Total
     $Output = fopen ($LocalFile, "a"); 
     ftruncate ($Output, 0);
     fseek($Output,0);
     fwrite($Output, $WUs);
     fclose($Output);
    }
   }

   //Read Total from Local File
   $Local=@fopen ($LocalFile, "r");
   $WUs=fgets($Local,200);
   fclose($Local);


   //Build Text String
   $Text=$PreText . "\r\n" . $WUs . " " . $PostText;

   //Create Image
   $size = ImageTTFBbox ($FontSize, 0, $FontFile , $Text);

   $im_x=abs($size[4]-$size[0]);
   $im_y=abs($size[5]-$size[1]);

   if (substr($ImageURL,strlen($ImageURL)-3,3)=="jpg")
   {
    //Create a Sig image based on a JPEG
    Header("Content-type: image/jpeg");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromJPEG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImageJpeg ($im);
    ImageDestroy ($im);
   }
   elseif (substr($ImageURL,strlen($ImageURL)-3,3)=="png")
   {
    //Create a Sig image based on a PNG
    Header("Content-type: image/png");
    Header("Expires: " . gmdate("D, d M Y H:i:s", time() + 900) . " GMT");
    $im_size = GetImageSize ($ImageURL); 
    $imageWidth = $im_size[0];
    $imageHeight = $im_size[1];
    $im = ImageCreateFromPNG($ImageURL); 
    $text_color = imagecolorclosest ($im, $TextRed, $TextGreen, $TextBlue);
    if ($TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
    if ($TextY>$imageHeight){$TextY=$imageHeight-2;}
    imagettftext ($im, $FontSize, 0, $TextX, $TextY, $text_color, $FontFile, $Text);
    ImagePNG ($im);
    ImageDestroy ($im);
   }
?>

Should be ok now. :)
 
Last edited:
thanks mate.

Thats cleared up two of the errors. Now i'm getting just this one;

Fatal error: Call to undefined function: imagettfbbox() in /mnt/web_b/d28/s24/a000ioo2/www/php/sig.php on line 72
 
Back
Top Bottom