Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A few questions

Status
Not open for further replies.

Inssider

Technical User
Aug 24, 2000
49
US
How much is the speed at which PHP code is processed affected by code size? For instance comments increase file size. And is it worth the time to go back and clean up all my code to combine/shorten loops, database calls, etc. in order to speed up the scripts? Will there be a worthwhile speed increase?

Also, is there a way to search for a word or phrase across many blobs in a MySQL database? Say I have a forum that stores messages in blobs, and I want to set up a search engine. Can I do this?

And is there a more elegant and easier way to format dates other than the way I have set up?
function echodate($date)
{
$canceldash=explode("-",$date);
$year=$canceldash[0];
$month=$canceldash[1];
$dashgone=$canceldash[2];
$cancelspace=explode(" ",$dashgone);
$day=$cancelspace[0];
$spacegone=$cancelspace[1];
$cancelcolon=explode(":",$spacegone);
$hour=$cancelcolon[0];
$minute=$cancelcolon[1];
$second=$cancelcolon[2];
return date("M dS H:i",mktime($hour,$minute,$second,$month,$day,$year));
}
where $date is a datetime value as obtained from a MySQL result. This way works, but is clunky and probably sacrifices a good deal of speed.

Last things: the way I have my site set up, on every page I set $title, $valign, $pagename, etc. values before including a site-universal header, outputting page content, and then including a site-universal footer file. Site-wide-needed file locations, among other things, are stored in a config object so I can update locations easily. Anyway, in my header/footer files and my config object, I've set addresses like "sitegfx/divinssider.gif" etc. However, these only work if all pages are contained in the same folder, so that the relative addresses work. Is there a way for me to easily set up my pages so they can be in their own directories and still use the header/footer/config locations? As it is now, they're all jumbled up into one directory except for graphics, and if I try to move pages to directories I end up trying to display "sitegfx/divinssider.gif" from a folder other than the root and so the file won't exist.

Thanks.
 
Okay. Let's see here.

1. Not really at all. You can put an infinite amount of commenting in your code and not sacrifice any speed. It's probably a good idea to do this, in fact. :) Cleaning up code is a good thing, but it probably won't save you enough time to sacrifice readability, so weigh it out like that.

2. Yes. In the more recent versions of MySQL. Read for more information.

3. Since the datetime format in MySQL is static, you could use a regex to take care of the parsing. e.g.

function echodate($date) {
preg_match("/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})/",$date,$datearray);
if(count($datearray) == 8) {
return date("M dS H:i",mktime($datearray[5],$datearray[6],$datearray[7],$datearray[3],$datearray[4],$datearray[2]));
} else {
// Exception handler
}
}
I'm doing this from my head, so pardon me if I screwed up there. So long as you get the idea. As stated in part 1, this probably isn't going to speed things up a great deal, but it is easier to interpret, in my opinion.

4. Good setup. For the folders, just enter the path from the root directory in your config files. Instead of "sitegfx/divinssider.gif", use something like "/mywebsite/sitegfx/divinssider.gif". This will first jump to the root dir before traversing the rest of the path and you're good to go.

Hope this helps.

brendanc@icehouse.net
 
Okay thanks a lot. I know HTML download size is affected greatly by the actual ASCII file size, so I didn't want to have fat PHP code =] I'll try out the regex, haven't studied that aspect yet myself, so I'll take your word for it =]

Thanks a lot.
 
One of the things to consider regarding the download time for the HTML is that PHP is a server-side language. None of the PHP code or comments are sent to the user... The size of the HTML document will not suffer.

Take care,

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top