Structuring a Large PHP Project?

If starting a new project, consider using a Framework, or taking a look at how they do it Frameworks usually either dictate, or suggest, a directory structure Even if you don't end up using one: The way they structure their projects usually comes from tons and tons of experience I personally like the Zend Framework way of structuring, and its Autoloader, best. But there are several options and philosophies out there Framework questions: What PHP Framework to choose Best PHP framework for an experienced PHP developer? More Framework questions Generally related: In a PHP project, how do you organize and access your helper objects?

How to use PHP for large projects?

If starting a new project, consider using a Framework, or taking a look at how they do it. Frameworks usually either dictate, or suggest, a directory structure. Even if you don't end up using one: The way they structure their projects usually comes from tons and tons of experience.

I personally like the Zend Framework way of structuring, and its Autoloader, best. But there are several options and philosophies out there. Framework questions: What PHP Framework to choose Best PHP framework for an experienced PHP developer?

More Framework questions.... Generally related: In a PHP project, how do you organize and access your helper objects? How to use PHP for large projects?

I would recommend having only one file in root folder, being index. Php, and make this file include everything else that's needed based on requests received. If you do OOP, it's usually convienient to put your classes into folder structure that mimics your namespacing (whether simulated in PHP This allows for easy autoloading of classes.

1 I belive this is a beginning to making alot of bloat in your code, and unfortunately, this way is quite common. – BarsMonster Sep 2 '10 at 9:42 1 @BarsMonster Since the question asks for large PHP projects and not some smallish site, it's a reasonable suggestion to use FrontController. The folder structure is also a good call.It's PEAR convention afaik.

Compensating downvote with upvote. – Gordon Sep 2 '10 at 9:45 @BarsMonster: Arguably, if you put one huge switch() statement into index. Php it's possobily the worst way to do this.

However there are ways to do it in much leaner way (I'll refer you to frameworks which you mentioned in your answer) – Mchl Sep 2 '10 at 10:01 Ok, you win :-) – BarsMonster Sep 2 '10 at 10:12.

I'd say it doesn't matter too much how you layout your application folderwise. Having files is a necessity and it has some impact on the application. Address that impact.It's not how you layout your folders, it's why.

Find some ideas below. For security, you should put only those scripts into the webroot that are actually supposed to be directly servable to the world. Also, if you have files created during runtime, make sure those don't get overwritten when you deploy/update your application to your server.

Whether you address that in your deployment routine or by the folder layout is up to you. For performance, take into account that including files/code that are/is not needed for a particular request will unneccessarily slow down your app.So does having many include_paths to search in. Make sure PHP can find the files it needs fast.

For maintainability, use common sense. There is no rule that you have to have one file per class. There is also no rule that you have to follow PEAR file layout.

PEAR is a widespread convention and a reasonable one, but throw your files into a single folder if it makes sense for this particular application. IMO, an application is not the files, it's the code within. It's much more important to have your code well organized than your files.

Having a messy file layout is much less an issue than having a messy architecture.

Personally I use the way you described in last paragraph, and find it useful, clean & fast to execure. Be sure to move all common stuff in common libs/files, in no way should you copy/paste. Another (common) way of structuring is when you use some frameworks, which usually enforce some specific project structure.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions