Using PHP framework

I just tried a php framework.

I don’t want to use php as a web server. I don’t want that php handles not found errors. And I don’t want to have an index.php for all of the requestes. I don’t think that it’s good.
And I don’t like to use something that I don’t know how it works. But I want to use some useful functions and classes that other good developers have created.

Please help me what to do. What is the solution? Can I have a custom PHP framework? Thanks.

People use custom PHP frameworks all the time. You can find one online you like that suits your needs, or take pieces of scripts and functionality and build your own.

I suggest you start with doing some Google research on what PHP is, exactly - it sounds like you’re uncertain of what it is, or more specifically what it can do for you. PHP isn’t a web server, but it is a server side language. And you don’t have to use .php page endings, if you’re using URL rewriting of some kind - but you do have to use PHP files to use PHP :wink:

Hope that’s a help. I’d search for a better understanding of what PHP is and maybe learn some basics (Sitepoint has some awesome articles) about it before looking any further.

1 Like

Here is a news flash for you. It is unlikely you will ever know how something works without digging into. If that is the reason you’re not able to use a framework than good luck in this profession. In real world as engineers we work with other peoples code everyday and it is our job to figure it out to point it can be managed and changed. Stop being so stubborn and learn something new.

I would love to hear why you think a front end controller should be an anti-pattern.

That is what frameworks such as; Symfony 2, Laravel and even the well known CMS’s are for. None of which you will understand off the bat. Read the docs and use one for a real project. That is only way to learn them. Just dismissing them because they are to hard to learn is how a failure/loser thinks.

2 Likes

By what you’re saying here, I’m assuming you brushed against Laravel.

You don’t need to use PHP as a web server, and when using any web server like Nginx or Apache, you can have them handle not found pages. PHP can be used to pretty them up or generate custom output, but you’re by no means constrained to it.
You definitely should use a single point of entry (index.php) because it bootstraps (prepares) your application and makes sure everything is loaded up properly, so that’s a best practice you better learn to love, and fast.

I can get behind that, but the solution is not to run away from a framework, but to go inside the code and learn how it works.

This is where Composer comes in. Using Composer you can easily install pre-made packages from Packagist.org and re-use code others before you have built with great ease. With the help of Composer, you can build your custom framework easily.

But like @jeffreylees says, you’re probably confused as to what PHP actually is, and what it can do for you. Perhaps starting with something simpler than a framework might be a good approach.

4 Likes

I can get behind that, but the solution is not to run away from a framework, but to go inside the code and learn how it works.

Couldn’t agree more! Experience is one of the best teachers you can ever have…

2 Likes

He might be coming from a Python or Java background. In frameworks for those languages the webserver is directed to invoke a program when any request is made for a file in the directory, and nothing actually has to exist in that directory path, unlike PHP where, at a minimum, there must be an index.php or similar file for mod_rewrite to call.

If you want to use their code you’ll have to play by the rules that code expects to work with.

1 Like

Because I like apache! It’s very powerful (log, benchmark, etc).

What are you talking about… php is an application language and apache a web server. The server in php 5.3? isn’t meant for production as already stated.

2 Likes

I know what are php and web server exactly. I’m saying that PHP shouldn’t do the web server’s job. like handle all the requestes (with one index.php file).

Why ?

Once you have used this method you will never look back. It is OH so much easier to change a complete online installation just by changing a single line in index.php.

Because Apache is supposed to do that. I can benchmark with webgrind and I can log the requests for different files that god knows how useful it is!)
Ok, Can anyone tell me that how the big websites handle this? (like twitter, facebook, amazon, etc.)

The Facebook SDK for iOS is a framework that you add to your Xcode project.

http://docs.aws.amazon.com/amazonswf/latest/awsflowguide/welcome.html

The AWS Flow Framework is a programming framework that simplifies the process of implementing a distributed asynchronous application while providing all the benefits of Amazon SWF.

1 Like

I just a a brief look at Webgrind and it is recommended to only use on your localhost?

I think that most Php Frameworks have similar reporting functions that may even be better than Webgrind.

CodeIgniter Framework has a Profiler Class detailing just about everything possible about the current page, benchmarks, classes used, memory usage, database, queries, http headers, config variables. Excellent log info and numerous file caching features. Also numerous database drivers I really like their file caching system, once again switched by changing a single variable.

Hey arian, I think there’s some misunderstanding here. As others have pointed out, using the front controller doesn’t mean that you route all requests through a single file - commonly, requests for static files (media/css/js) are handled directly by the webserver (apache/nginx or whatever) as it’s more efficient.

What others are trying to dissuade you from is having multiple entry points for your actual application, e.g. index.php, contact.php, about.php - as you’re duplicating code to do the necessary setup of your app each time.

Also, routing all your dynamic requests through a front controller won’t prevent logging. Apache will still keep a log of the actual URLs requested before they get re-routed through index.php.

4 Likes

This is the key point, I was going to make. +1 to @fretburner! :smile:

Maybe you’re considering the wrong tool for the job. If most all of your site is static files, or nearly static files, with common elements such as menus, headers and footers that rarely change, perhaps Harp would be a better choice. Harp’s output can be uploaded to any webserver you choose.

PHP is best used as a bridge between the outside world and a database of fast, ever changing data, where maintaining those files as statics would be an enormous or impossible chore.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.