Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2010, 12:29 PM   PM User | #1
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
batch file line addition

Hi. I want to add a single line of code to the very top of many hundreds of php pages.

Does anyone know of batch software that will do just that?

Thanks!

Terry
__________________
The difference between genius and stupidity is that genius has its limits. (Albert Einstein)
tpeck is offline   Reply With Quote
Old 02-19-2010, 01:14 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Are you sure that there are hundreds of pages, or is there one script that
dynamically generates those pages? Take this forum for example ... there
are thousands of pages, but it's really only 1 script that makes all of them.
There are really not thousands of pages.
mlseim is offline   Reply With Quote
Old 02-19-2010, 01:37 PM   PM User | #3
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
Yes, I'm sure.

It appears that there is a single line of code that you can add to a php page that speeds up the loading of the page:

Code:
<? ob_start("ob_gzhandler"); ?>
...but you have to put it at the very top of each php page.

It does work, but I have quite a few hundred pages that form part of a shopping cart (zencart) etc.

Adding that single line of code by hand will be quite time-consuming.
__________________
The difference between genius and stupidity is that genius has its limits. (Albert Einstein)
tpeck is offline   Reply With Quote
Old 02-19-2010, 02:06 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,748
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, there is a way to do this without editing you're php files using .htaccess and ini directives.
Assuming you're on Apache, you can put an auto_prepend call into you're .htaccess (which assumes you have AllowOverride for it).
Code:
php_value auto_prepend_file /path/to/autoprependfile.php
Use a full path to keep from crazyness happening, or you can put it in a known include_path.
With autoprependfile.php containing:
PHP Code:
<?php
ob_start
('ob_gzhandler');
?>
You won't need to auto append though, output buffering should flush itself at script termination.

May I inquire as to why so many php files though? I mean, I've moved pretty much exclusively to OOP in PHP, yet my library itself is now about 107 class files. Even when I was procedural, I think the most files I've ever created for an entire site was 24 excluding configuration files. Management of that alone was a horrid task - I had known PHP for maybe 3 years at that point, so there was still a lot I didn't know about it (such as OO hah).
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
tpeck (02-28-2010)
Old 02-19-2010, 04:15 PM   PM User | #5
DaiWelsh
New Coder

 
Join Date: Aug 2003
Location: Derby, UK
Posts: 97
Thanks: 0
Thanked 14 Times in 14 Posts
DaiWelsh is an unknown quantity at this point
If you do decide to amend the files, why not do it with a PHP script? Loop through dir (recursively if necessary), check if files are php (and any other logic you need), open and squirt in the extra line. 10 minutes php tops. If you don't have permissions then it might get harder, I would normally do a quick perl script on my local machine for a task like that but I don't have php installed locally, you might...

Would also be quite easy in vbscript if you fancy it..
DaiWelsh is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25 PM.


Advertisement
Log in to turn off these ads.