PHP Parser, worthwhile?
Moderator: General Moderators
PHP Parser, worthwhile?
Hi, i would like to ask, would it be worthwile for me to make a quick PHP code parser, how much will i gain? Here is my idea, the core of it really.
I have an encode and decode program, that takes a php file, strips off all comments and all spaces and formats it into a long block of code with no spaces no comments, very hard to read indeed. (but shouldn't it be faster?)
This process encode, will save a text file with the encoding information, that is it will contain the comments and the spaces previously stripped off, in case i want to take my code and edit it. I then use the decode and it will do that for me.
This is purely an idea, my aim is to hopefully to cut some of my overhead. Should my time be better spent trying to figure out how to use caching instead?
Thanks a bunch.
I have an encode and decode program, that takes a php file, strips off all comments and all spaces and formats it into a long block of code with no spaces no comments, very hard to read indeed. (but shouldn't it be faster?)
This process encode, will save a text file with the encoding information, that is it will contain the comments and the spaces previously stripped off, in case i want to take my code and edit it. I then use the decode and it will do that for me.
This is purely an idea, my aim is to hopefully to cut some of my overhead. Should my time be better spent trying to figure out how to use caching instead?
Thanks a bunch.
Re: PHP Parser, worthwhile?
Yes, you're time would be better using caching. As a matter of fact, caching AND an accellerator. Something like APC, or Turk McCache comes to mind.mikusan wrote: This is purely an idea, my aim is to hopefully to cut some of my overhead. Should my time be better spent trying to figure out how to use caching instead?
Thanks a bunch.
Now if you're like me and you use a lot of comments and you just can't get over being worried about the drain this has on performance, just put copies of your code without comments into production. Just keep a "commented" copy of your site for development and stuff.
Cheers,
BDKR
Google, AllTheWeb, Feedster. There are also sites like PHPBuilder.com. It has tons of tutorials on PHP and doing various things.mikusan wrote:Where do i start?
Any suggestions where can i find info on caching?
Also, what exactly are you doing? Caching isn't what I would do first. The first thing I would do is install an accellerator. I allready mentioned a couple.
However, worrying about that kind of thing is normally something that comes a little later in the development process if you know what I mean.
Just to say something to McGruff: I wouldn't have thought the comments made much of a difference either until Selkirk over at sitepoint did some benching and found that there is a penalty associated with parsing out comments as well as anything else. That's why an accellerator makes so much sense. The parsing phase of running a script is taken care and all that needs to be done is actual execution.
Cheers,
BDKR
Caching makes a lot of sense for site areas which aren't constantly updating - not something you'd use for a discussion forum however.mikusan wrote:Where do i start?
Any suggestions where can i find info on caching?
Use output buffering to grab a string which you can write to file. For example, if you normally finish off a script by including an html template where a bunch of page vars get echo'd out:
Code: Select all
<?php
ob_start();
include('html/template.htm');
$html = ob_get_contents();
ob_end_clean();
?>
Last edited by McGruff on Wed Aug 10, 2005 12:16 pm, edited 1 time in total.
All of my scripts are designed to concatenate the output and echo it only at the very end, i also use my own custom made parser class. Though i found that reloading the same page was kind of pointless, i wanted to start tackiling the problem by making what i described above, but then realized that perhpas caching was the best thing to do. Though i don't know where to start, but basically, say, when you go to my website for the first time, all the images will take away time at loading, but that should not happen at any subsequent loads. So if i can cache the images and that sorta stuff into the client's computer i think i can more than compensate for SECONDS of time!!
Correct me if i am wrong, and how exactly would i go ahead and start on that.
Thanks
Correct me if i am wrong, and how exactly would i go ahead and start on that.
Thanks
Interesting.BDKR wrote: Just to say something to McGruff: I wouldn't have thought the comments made much of a difference either until Selkirk over at sitepoint did some benching and found that there is a penalty associated with parsing out comments as well as anything else. That's why an accellerator makes so much sense. The parsing phase of running a script is taken care and all that needs to be done is actual execution.
Cheers,
BDKR