PHP Classes

PHP routing is good at-least for me

Recommend this page to a friend!

      PHP Classes blog  >  4 Reasons Why All PHP...  >  All threads  >  PHP routing is good at-least for me  >  (Un) Subscribe thread alerts  
Subject:PHP routing is good at-least for me
Summary:I like PHP level routing
Messages:6
Author:Hari K T
Date:2014-02-12 03:33:44
Update:2014-02-12 06:51:30
 

  1. PHP routing is good at-least for me   Reply   Report abuse  
Picture of Hari K T Hari K T - 2014-02-12 03:57:49
Regarding your opinion on routing at PHP level, I disagree.

Apache may be fast to perform the routing based on mod_rewrite, but hard for people to write the htaccess rules. PHP is much easier and if you still strongly feel the neeed for faster performance route why not a C implementation like Pux can be introduced ?

github.com/c9s/Pux

Benchmark with PHP routes.

github.com/c9s/Pux/issues/17#issuec ...

  2. Re: PHP routing is good at-least for me   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-02-12 04:28:52 - In reply to message 1 from Hari K T
No, there is no need to use mod_rewrite to do routing with Apache. Look at PHP Clases URLs, there are no .php URLs. mod_rewrite is never used.

It is a old trick of Apache that it is explained here.

phpclasses.org/discuss/blog/PHP-Cla ...

It can't be simpler than this. Requests are directed to the scripts that run your controllers. There is no need for front controllers to look at the URLs and match them against any of the controller URL patterns you need to match.

I may end up writing an article about this because you framework fans always assume the framework you are in love with is the best for everything. Consider the fact that you may not know all the best techniques.

  3. Re: PHP routing is good at-least for me   Reply   Report abuse  
Picture of Hari K T Hari K T - 2014-02-12 06:22:59 - In reply to message 2 from Manuel Lemos
> Consider the fact that you may not know all the best techniques.

Manuel Lemo, I agree with you. I don't really know all the best techniques and I am learning each day. But I still didn't get what you were telling in the thread.

It will be good if we can show some example.

If you are trying to explain like

1) Create the router object
2) add a route with the controller, action values.
3 ) Match the route based on thr request and dispatch it, then it is same as what Aura.Router is doing.

It is not full framework, but just components.

github.com/auraphp/Aura.Router/#dis ... and what I have pointed to Pux or many similar components are doing.

I will wait for your example to see how the best way / technique you are mentioning.

  4. Re: PHP routing is good at-least for me   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-02-12 06:27:06 - In reply to message 3 from Hari K T
What I mean is that if you put in your Apache configuration something like this, you will be telling that all requests to URLs that start with /blog/ will be handled by a PHP script named blog. In that PHP script named blog you just call your blog controller classes. No front controllers or mod_rewrite are needed.

<Files blog>
SetHandler application/x-httpd-php
</Files>

  5. Re: PHP routing is good at-least for me   Reply   Report abuse  
Picture of Hari K T Hari K T - 2014-02-12 06:45:00 - In reply to message 4 from Manuel Lemos
Thank you for the information.

I was not aware of this. But this has its own drawback if you at some point of time want to move to ngix or some other.

I don't know the real speed you are getting with this sort of technique though.

  6. Re: PHP routing is good at-least for me   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-02-12 06:51:30 - In reply to message 5 from Hari K T
That is the thing Rasmus was trying to make people pay more attention.

If you are using a certain setup, Apache for instance, it does not make sense to optimize for a different setup that is not what you are running.

If you are using MySQL, why are you checking on every request the type of database you are using? It won't change, so optimize for it.

Anyway, if you change to nginx one day, I don't know if there is anything like SetHandler for nginx, but in the worst case you can use their equivalent for mod_rewrite and make your request to /blog/* be handled as if they were going to /blog.php/* .