nikic / FastRoute

Fast request router for PHP
Other
5.12k stars 445 forks source link

Static contents #216

Closed girishpadia closed 4 years ago

girishpadia commented 4 years ago

I want to serve some static contents like "index.html" but couldn't find any working example for this. Could you please guide?

lcobucci commented 4 years ago

@giansalex that kind of thing is usually best handled by your web-server. Are you sure you want PHP to proxy static resources?

girishpadia commented 4 years ago

Thank you for response. OK I will handle through web server. I thought to serve everything through routing. :+1:

lcobucci commented 4 years ago

That's a task that would put extra load on the PHP-FPM worker pool (assuming you're using FPM) if handled by PHP, which is rather unnecessary since webservers can already do that extremely well.

However, if you do need to have extra logic (e.g. an authorisation layer) you may choose to have PHP doing that too. That does go beyond the scope of this library since it's about routing and not serving responses. In that case, you'd implement a handler that would open the file resources via PHP and stream them as the response content - but, again, that's something you implement yourself or (better) use a "micro-framework" like Mezzio or SlimPHP to help you with.

lcobucci commented 4 years ago

Will close this then, glad to hear the webserver approach is enough for you :+1: