auto prepend file versus require() or require_once()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
finderetf
Forum Newbie
Posts: 2
Joined: Thu Dec 16, 2010 7:39 am

auto prepend file versus require() or require_once()

Post by finderetf »

I'm using require_once() method, and I need to load a lot of files, but depending by case, I load certain php file, not all at once. I'm trying to speed up my application, and I'm wondering if I can put all of them into php.ini file as auto prepend files.
Question : Does auto prepend file do the same as requre() does?I'm speaking about performances. Precisely, if I put
auto prepend file /Files/file1.php
auto prepend file /Files/file2.php
auto prepend file /Files/file3.php
auto prepend file /Files/file4.php

is it same as (time to get those files, or auto prepend files add them on start of webserver)

require /Files/file1.php
require /Files/file2.php
require /Files/file3.php
require /Files/file4.php

Thanks!!!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: auto prepend file versus require() or require_once()

Post by s.dot »

I am not sure, as I have never done this.. but performance wise there are many many more factors that would come into play before including a file would.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
finderetf
Forum Newbie
Posts: 2
Joined: Thu Dec 16, 2010 7:39 am

Re: auto prepend file versus require() or require_once()

Post by finderetf »

I have one access point php file. Let's call it ap.php. There are directed all of my ajax calls.If I can have 1000 different ajax calls, you can imagine what code I have behind ap.php . I think I can speed it up, but only I'm interested to know if auto prepend file put php file into php core, or just add it when I call ap.php and waste my time ???
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: auto prepend file versus require() or require_once()

Post by Darhazer »

require is faster than require_once
also, make sure you have opcode cache (APC for example)

auto-prepend-file can not be conditional as require.
the result will be as you have require() for every one of the files at beginning of every script (not only at ap.php)

Also, in order to speed up your application, measure the performance and find the bottlenecks. It's possible that this optimization which you are doing gives you few ms improvement, while single like of code consumes several seconds.
Post Reply