A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearRolling and packing PHP scripts - page 1
User InfoPosts
Rolling and packing PHP scripts#1
I was just reading over this thread where the pros and cons of using include_once and require_once were being debated. From that discussion (particularly Ambush Commander's answer), I've taken away the fact(?) that any sort of include in PHP is inherently expensive, since it requires the processor to parse a new file into OP codes and so on.

This got me to thinking.

I have written a small script which will "roll" a number of Javascript files into one (appending the all contents into another file), such that it can be packed to reduce HTTP requests and overall bandwidth usage.

Typically for my PHP applications, I have one "includes.php" file which is included on each page, and that then includes all the classes and other libraries which I need. (I know this isn't probably the best practise, but it works - the __autoload feature of PHP5 is making this better in any case).

Should I apply the same "rolling" technique on my PHP files?

I know of that saying about premature optimisation being evil, but let's take this question as theoretical, ok?

posted date: 2008-12-17 06:54:00

Re: Rolling and packing PHP scripts#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-17 06:54:01

Re: Rolling and packing PHP scripts#3
As you've said: "premature optimisation ...". Then again, if you're worried about performance, use an opcode cache like APC, which makes this problem almost disappear.

posted date: 2008-12-17 07:12:00

Re: Rolling and packing PHP scripts#4
That would depend somewhat on whether it was more work to parse several small files or to parse one big one. If you require files on an as-needed basis (not saying you necessarily should do things that way ) then presumably for some execution paths there would be considerably less compilation required than if all your code was rolled into one big PHP file that the parser had to encode the entirety of whether it was needed or not.In keeping with the question, this is thinking aloud more than expertise on the internals of the PHP runtime, - it doesn't sound as though there is any real world benefit to getting too involved with this at all. If you run into a serious slowdown in your PHP I would be very surprised if the use of require_once turned out to be the bottleneck.

posted date: 2008-12-17 07:39:00

Re: Rolling and packing PHP scripts#5
This isn't an answer to your direct question, just about your "js packing". If you leave your javascript files alone and allow them to be included individually in the HTML source, the browser will cache those files. Then on subsequent requests when the browser requests the same javascript file, your server will return a 304 not modified header and the browser will use the cached version. However if your "packing" the javascript files together on every request, the browser will re-download the file on every page load.

posted date: 2008-12-17 07:46:00

Re: Rolling and packing PHP scripts#6
no no - the packing is only done once, before deploying to the server. I've written a blog post about the method I use here: spadgos.com/?p=32

posted date: 2008-12-17 16:06:00

Re: Rolling and packing PHP scripts#7
There is a problem with Apache/PHP on Windows which causes the application to be extremely slow when loading or even touching too many files (page which loads approx. 50-100 files may spend few seconds only with file business). This problem appears both with including/requiring and working with files (fopen, file_get_contents etc).So if you (or more likely anybody else, due to the age of this post) will ever run your app on apache/windows, reducing the number of loaded files is absolutely necessary for you. Combine more PHP classes into one file (an automated script for it would be useful, I haven't found one yet) or be careful to not touch any unneeded file in your app.

posted date: 2012-11-10 02:36:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.