...

View Full Version : batch file line addition



tpeck
02-19-2010, 12:29 PM
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

mlseim
02-19-2010, 01:14 PM
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.

tpeck
02-19-2010, 01:37 PM
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:


<? 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.

Fou-Lu
02-19-2010, 02:06 PM
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).


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
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).

DaiWelsh
02-19-2010, 04:15 PM
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.. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum