/    Sign up×
Community /Pin to ProfileBookmark

Power entire website from one file?

I am planning on running a website (3000+ pages) with only one file (index.php). Is this a good idea? What are the advantages and disadvantages?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscMar 20.2009 — Depends. Is you index.php file going to be so full of code to handle all the different potential query strings that will show the user the dynamic content that they requested that your index file will be megabytes in length? If so, then yes - it is a bad idea.
Copy linkTweet thisAlerts:
@stephan_gerlachauthorMar 20.2009 — Yes it will be but since it is heavily using databases and a good structure at the moment the file is only 63KB (1700 lines) big and this should probably power already about 1000 pages. Is this OK?
Copy linkTweet thisAlerts:
@toicontienMar 20.2009 — Many MVC frameworks for PHP run off this approach, including Motortopia.com. It uses the Code Igniter PHP framework and hosts tens of thousands of pages. Everything is routed through the index.php file -- and its only 3.5 KB in size... not counting any other file in the framework. ?
Copy linkTweet thisAlerts:
@NogDogMar 20.2009 — "OK" can be very subjective, and "running a website with only one file" can have many implementations of varying qualities of "OK".

Personally, I consider any file more than a few hundred lines to be too big and a red flag that it's time for re-factoring/redesigning.

Are you using some method to provide user-/search engine-friendly URLs, or is every page going to be accessed by some cryptic URL query string?
Copy linkTweet thisAlerts:
@svidgenMar 20.2009 — It's quite typical to run everything through a single PHP script, conditionally including additional scripts and functions as necessary. I think the main script (index.php) is usually pretty minimal though--if there is any functionality that isn't used with every request, you may want to make those functions conditional includes or [I]require_once[/I]'s.

In any case, with a good caching addon, this basic method is pretty efficient.
Copy linkTweet thisAlerts:
@aj_nscMar 21.2009 — I'm glad to see that people tend to have the same point of view that I do. I am in no way an expert with building websites with php, but I am not a beginner either.

I like the last post the best and it really illustrates the key to what you need to do:


if there is any functionality that isn't used with every request, you may want to make those functions conditional includes or require_once's.
[/quote]


If in your index file (of 1700 lines!!!!!!!) you find some if statement or while loop that would only be necessary for a handful out of the potentially hundreds of variables you could get through your query string, then it's time to put those in a separate file and use require.

My bet is that, if it's 1700 lines long, you've got more than a few parts that you can take out and put in separate files.

It's not whether the server can handle this type of website, because, as most people pointed out, it's fairly common, but for your own sanity/organization skills, it's better to keep things clean.
×

Success!

Help @stephan_gerlach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...