Thursday, June 18, 2015

H2OとPHPを組み合わせるの、超簡単です(もしくはmod_rewriteが不要な理由)

FastCGI対応機能がH2Oにマージされたことを受けて、uzullaさんが「H2OでPHP(がちょっとだけ動くまで)」という記事を書いてくださっています。

ありがたやありがたや。

その中で、
http://hoge/entry/1 みたいなのをphpにマップする方法はまだよくわかってません。その内しらべます

github.comを読む限り
FastCGI (or PHP) applications should be as easily configurable as it is for the Apache HTTP server
ということで、やったぜ!ってなるんですけど、nginxはもとより、Apacheにおいても現状ルーターをつかっているようなアプリだとhtaccessをいちいちかかないといけないので、Apacheみたいなスタイルが楽なのか?というとちょっと疑問があります。

(たとえば以下みたいなの)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
ここらへんがスッっとかけないと、まあApache、nginx同様にH2Oの設定のタレが必要になるかなあ、という感じはあります。
いやはや、まったくそのとおりなわけです。

ちなみにこの手のことをNginxでやろうとするともっと難しくて、以下のようにtry_filesfastcgi_split_path_infoを使わないと脆弱性が発生するなんて話があるそうです(参照: Setting up PHP-FastCGI and nginx? Don’t trust the tutorials: check your configuration! » Neal Poole)。これ、みんなちゃんとできてるんですかね?
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
   try_files $uri =404;

   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   include fastcgi_params;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   fastcgi_pass php;
}

こんな難しい設定、書けるわけないだろうが!!!!!!!

というわけで、H2Oの場合はもっと簡単に設定できるようになっています。以下のような感じ。
paths:
  "/":
    # /path/to/doc-root以下の静的ファイルを返す(存在した場合)
    file.dir: /path/to/doc-root
    # 存在しなければ、/index.php/ に内部転送
    redirect:                     
      url: /index.php/
      internal: YES
      status: 307

単純ですね。どうなってるかはコメントを見れば自明かとも思いますが、以下解説します。

実は、H2Oの設定ファイルにおいては、1つのパスに複数のハンドラを設定することができるのです。

複数のハンドラが設定されている場合、H2O は有効なレスポンスが生成できるまで、ハンドラを順次実行していきます。つまり、コメントにあるように、ファイルが存在すればそれを返すし、存在しなければ /index.php/ 以下にリクエストを内部的に転送し、その転送した結果の応答をクライアントに返すわけです。

わかりやすいですね。簡単ですね。


少し理屈っぽい話をすると、mod_rewriteのようなリクエストを書き換える黒魔術は、おおむね3種類の目的に使われてきました。第1の目的は、複数のローカルのディレクトリツリーを重ね合わせてひとつのhttpサイトとして表示すること。第2の目的は、uzullaさんが指摘したような、特定の条件をもつ以外のURLの処理を、FastCGIやアプリケーションサーバに委譲すること。第3の目的は、User-Agentや言語設定によって異なる応答を返すこと。

ですが、前2者を実現するためだけならば、正規表現を用いてURLを書き換えるような手法は過剰にすぎて管理がしづらかったわけです。H2OにおけるPHP対応においては、この点を意識し、複数のハンドラの連鎖を可能にすることで、設定が安全簡潔にできるようにしたのでした。

ちなみに、uzullaさんの例ではphp-fpmを使っていますが、H2Oはphp-cgiを自分で管理することができるので、小規模なウェブサイトにおいては、
file.custom-handler:          
  extension: .php
  fastcgi.spawn: "PHP_FCGI_CHILDREN=10 exec /usr/bin/php-cgi"
のように書くと、別途FastCGIデーモンを管理する必要がなくなって、より幸せになれるでしょう(名前はphp-cgiでも、この設定においてはFastCGIとして動作します)。


最後になりますが、ここで説明したFastCGI対応機能を盛り込んだH2Oバージョン1.3は今朝方リリースされたので、PHPerの皆様もそれ以外の皆様も、お試しいただければ幸甚に存じます。

リンク先のリリース告知エントリにも書いてあるけど、他のウェブサーバより表示速度(first-paint time)が、かなり速いですよ!

129 comments:

  1. This is great do you have a catologue if so I would love one to share with friends and family.
    ICC T20 World Cup 2016
    Australia vs India time table

    ReplyDelete
  2. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    animal jam | five nights at freddy's | hotmail login

    ReplyDelete
  3. Oletusasetus on kytt Helsingin seudun reittiopasta. Click To Discover More! Mind Map: by its intuitive way to show informationIit is a fantastic brain storming tool to arrange your life or ideas.

    ReplyDelete
  4. Share tips and recommendations with friends and other travelers. downlodable manuals -Designed for preschoolers- no confusing menus or navigation.

    ReplyDelete
  5. Features:- Take care of a pregnant mommy and her new born kids. Look for it Change skins in a flash without ever stopping the music.

    ReplyDelete
  6. Tidichi will together with you to build a community to search and share useful place for everyone. download torrent Search exhibitors, speakers or seminarsSearch through lists of exhibitors speakers or seminars.

    ReplyDelete
  7. And of course, you can share any item with friends via e-mail, Twitter, Facebook, or Tumblr. checkout this. We listen to our customer&'s suggestions and that&'s why version 2.

    ReplyDelete
  8. This application has subtitles in ENGLISH & CHINESE, More Languages to Follow. downloadbooks.ru Youve probably heard about the stunning flowers from Roses Only, but did you know about our other beautiful and unique gifts.

    ReplyDelete
  9. Or you can simple standing close to enemies and get experience/money when they are killed by weapon buildings, but it's less than being kill by you. download freeware Some you've probably heard of, and some you've most likely haven't.

    ReplyDelete
  10. To protect their children, Sean and Yana send them to stay with a powerful family friend on an orbiting space station. downloadgoodfilesblog.top Support locates your current location quickly without internet connection(iPhone only).

    ReplyDelete
  11. You can dl lots of shows for free like anime or movies. downloadingstarted.me Take multiple photos AND videos, and have them uploaded to JIRA, for fast triage, search and reporting.

    ReplyDelete
  12. http://khairyayman.eklablog.com/http-emc-mee-com-transfer-furniture-almadina-almonawara-html-a126376958 شركة نقل عفش بالمدينة المنورة
    http://khairyayman.eklablog.com/http-emc-mee-com-transfer-furniture-jeddah-html-a126377054 شركة نقل عفش بجدة
    http://khairyayman.eklablog.com/http-emc-mee-com-movers-in-riyadh-company-html-a126376966 شركة نقل عفش بالرياض
    http://khairyayman.eklablog.com/http-www-east-eldmam-com-a126377148 شركة نقل عفش بالدمام
    https://forums.ipa.edu.sa/vb4/member.php?202-%D9%85%D8%AD%D9%85%D8%AF-%D8%AE%D9%8A%D8%B1%D9%8A

    ReplyDelete
  13. Capture meeting notes using the voice-text capability of your phone. http://greatdownloadfiles.gdn Smash through 150 epic levels of castle crashing action, then expand your kingdom with the powerful build-and-share level editor.

    ReplyDelete
  14. The true power of the app lies in the search feature. downloadsoftwarefromalexis.online We had no idea where to even find a PIN, so we went to the Web site to see if we had to create an account to get one.

    ReplyDelete
  15. Don't be surprised if the game gives you an illusion that this is a 36 in 1 game. downloadornot.me But it's not that easy, why would monsters appear unarmed.

    ReplyDelete
  16. From manastone: Is the game Three Kingdoms too difficult. downloadfreethingshere.gdn Makes it possible to make your own games, what more can I say?

    ReplyDelete
  17. Your subscription includes access to this app, online, mobile website, e-newspaper and, if you choose, home delivery of the print edition. downloadfromthisblog.gdn As daily fluctuations of your portfolio might not show the tendency of your portfolio over time, this view helps you to get an overview.

    ReplyDelete
  18. The article you have shared here very good. This is really interesting information for me. Thanks for sharing!
    192.168.1.1 login |gmail signin

    ReplyDelete
  19. And you can follow the many links to discover more details in a concise view. downlodable serial numbers Note: House Hunter Pro is not a search tool or tied to any MLS system.

    ReplyDelete
  20. If You Want Watch IPL Live Stream Then Visit www.crickspo.com, it also provide IPL Live ScoreCheck IPL Updates, IPL News, Ball By Ball Score, Men of the atch, men of the series, who won the toss today etc.

    ReplyDelete
  21. You guys are really doing great work. I am sure you're doing research to provide such kind of stuff to us. Feeling proud that people like you still exist in the world.
    ipl live score
    free ipl score
    ipl live stream
    ipl final 2018
    ipl live streaming
    ipl final score
    ipl live stream 2018
    ipl live score 2018
    ipl 2018 Schedule match
    watch ipl online live

    ReplyDelete
  22. Cricket could be a bat-and-ball game vie between 2 groups of 11 players every on a cricket field, at the centre of that could be a rectangular 22-yard-long (20 metres) pitch with a target at every finish referred to as the wicket (a set of 3 picket stumps upon that 2 bails sit).
    ipl live score
    ipl score live
    free ipl score
    ipl final live streaming
    ipl final 2018
    ipl live streaming
    ipl final score
    ipl live stream 2018
    ipl live score 2018
    ipl Schedule 2018
    watch ipl online live
    ipl live score card
    ipl final
    ipl live stream
    live ipl score
    extra cover.net
    today ipl live score

    ReplyDelete
  23. Webroot.com/safe is a protection software solution that communicates with the cloud avoiding the hassle to manage the signature updates to deploy. for office setup visit office.com/setup

    ReplyDelete
  24. seo is good process for rankingWhat is seo process What is pbn networksDigital Marketing Career earn money online by Digital MarketingWhat is seo scope of seoHow to convert traffic into leads
    Digital Marketing course in faridabad

    ReplyDelete
  25. tips to earn money online How to earn money online learn at webhelpy

    what is pbn networks Learn more about PBN networks

    what is seo process Learn about seo and seo process

    ReplyDelete
  26. digital marketing course in faridabad Best digital marketing course in Faridabad at Webhelpy

    Digital Marketing Career  Build your Career with Digital Marketing

    How to convert traffic into leads  Learn lead generation at Webhelpy

    ReplyDelete
  27. buy gst ebook to make law more clear

    gst ebook to better understand gst

    buy online gst ebook

    gst ebook from lawcrux

    gst consultant in india

    buy best gst book

     

     

     

     

     

    ReplyDelete
  28. Valentine Week List 2019  love day in February

    Happy Anniversary Wishes Happy Anniversary Messages for Husband/ Wife

    Best digital marketing course in Faridabad Webhelpy is the best digital marketing training provider

    Happy Maha Shivratri Date Maha Shiv Ratri Wishes Images 2019 pooja vidhi

    SEO training in Faridabad Webhelpy is the best place to learn SEO

    ReplyDelete
  29. gst Advisors in Faridabad  to get more details in indirect tax
    Professional Tax Consultant in Faridabad
    digital book on gst ebook 
    gst consultants in india
    gst consultancy in india
    indirect tax consultancy in india to make the law more clear
    indirect tax consultancy in faridabad
    Professional Tax Consultant in Faridabad best tax consultant
    gst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.

    ReplyDelete
  30. gst Advisors in Faridabad  to get more details in indirect tax
    Professional Tax Consultant in Faridabad
    digital book on gst ebook 
    gst consultants in india
    gst consultancy in india
    indirect tax consultancy in india to make the law more clear
    indirect tax consultancy in faridabad
    Professional Tax Consultant in Faridabad best tax consultant
    gst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.

    ReplyDelete
  31. The Tango Yogi a youtube channel

    https://www.youtube.com/channel/UCU9LIxJGG8B09ZVnShbNs2Q

    ReplyDelete
  32. gst  best gst consultancygst Advisors in Faridabad  to get more details in indirect taxProfessional Tax Consultant in Faridabaddigital book on gst ebook gst consultants in indiagst consultancy in indiaindirect tax consultancy in india to make the law more clearindirect tax consultancy in faridabadProfessional Tax Consultant in Faridabad best tax consultantgst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.buy gst ebookonline buy gst ebookgst ebook software gst book online gst ebookonline buy gst book  

    ReplyDelete

  33. Awesom blog and great information. Your article has really peaked my interest. I am going to bookmark your website and keep checking for new details about once per week.

    happy Holi status for whatsapp
    Holi messages for friends
    holi images for lovers
    unique WiFi names for your network

    ReplyDelete
  34. gst  best gst consultancygst Advisors in Faridabad  to get more details in indirect taxProfessional Tax Consultant in Faridabaddigital book on gst ebook gst consultants in indiagst consultancy in indiaindirect tax consultancy in india to make the law more clearindirect tax consultancy in faridabadProfessional Tax Consultant in Faridabad best tax consultantgst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.buy gst ebookonline buy gst ebookgst ebook software gst book online gst ebookonline buy gst book  

    ReplyDelete
  35. Reiki first degree training in Faridabad | Vedic Seeds Astro Vastu Reiki first degree training in Faridabad | Vedic Seeds Astro Vastu – Reiki is helpful alternate medical therapy that help to recover

    ReplyDelete
  36. Reiki second degree training in Faridabad | Vedic Seeds Astro Vastu Reiki second degree training in Faridabad | Vedic Seeds Astro Vastu – Reiki is helpful alternate medical therapy that help to recover

    ReplyDelete
  37. Vedic Seeds Astro Vastu a top astrologer deals in providing career astrology based services and advice along with astro insights. Vedic seeds provide you all services remedies to help in your trouble. Do your karma make your future.We believe in results and benefits which you get.
    To Get more information visit at:www.vedicseedsastrovastu.com

    ReplyDelete
  38. Vedic seeds provide you all services remedies to help in your trouble. ``Do you karma make your future`` We believe in results and benefits which you get.If you have questions about your future, the answers are in the palm of your hands! We are with you now and after your work done, for your services.To get to the questions that arise in everyday get in here to introduce you to vedic Seeds Astro Vastu, who is one of astrologer in Faridabad in the service of society for more information .... http://www.vedicseedsastrovastu.com/

    ReplyDelete
  39. Vedic seeds provide you all services remedies to help in your trouble. ``Do you karma make your future`` We believe in results and benefits which you get.
    If you have questions about your future, the answers are in the palm of your hands! We are with you now and after your work done, for your services.To get to the questions that arise in everyday get in here to introduce you to vedic Seeds Astro Vastu, who is one of astrologer in Faridabad in the service of society more information .... http://www.vedicseedsastrovastu.com/

    ReplyDelete
  40. gst  best gst consultancygst Advisors in Faridabad  to get more details in indirect taxProfessional Tax Consultant in Faridabaddigital book on gst ebook gst consultants in indiagst consultancy in indiaindirect tax consultancy in india to make the law more clearindirect tax consultancy in faridabadProfessional Tax Consultant in Faridabad best tax consultantgst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.buy gst ebookonline buy gst ebookgst ebook software gst book online gst ebookonline buy gst book  

    ReplyDelete
  41. Best GST consultancy Lawcrux advisors are the best GST consultancy in India
    gst Advisors in Faridabad  to get more details in indirect tax
    Professional Tax Consultant in Faridabad
    digital book on gst ebook 
    gst consultants in india
    gst consultancy in india
    indirect tax consultancy in india to make the law more clear
    indirect tax consultancy in Faridabad
    Professional Tax Consultant in Faridabad best tax consultant
    gst ebook To make the law more clear, we provide you with the elaborative interpretation of the law in this GST E-Book.
    Best GST ebook which is based on indirect taxes
    online buy gst ebook FTP, Fema, Custom, Service Tax, Excise
    GST ebook software for professionals
    GST Ebook best ebook based on indirect taxation
    online GST ebook on GST
    online buy GST book

    ReplyDelete
  42. โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

    ReplyDelete
  43. https://jeff-vogel.blogspot.com/2015/07/indie-games-refunds-terror-and-taking.html?showComment=1558764476861#c8641824850897407459

    ReplyDelete
  44. dog walking harnessdog walking harness
    buy latest girl clothes onlinebuy latest girl clothes online
    latest fashion trend for femalelatest fashion trend for female
    ariana grande latest merchariana grande latest merch

    ReplyDelete


  45. chris brown clothing latest collection of chris browns
    browns clothing latest collection of chris browns clothing

    ReplyDelete
  46. https://www.theviralvista.com/new-oppo-mobile-phones-under-30000-rs/

    ReplyDelete
  47. https://www.theviralvista.com/new-oppo-mobile-phones-under-30000-rs/

    ReplyDelete
  48. https://www.theviralvista.com/new-xiaomi-mobile-phones-under-30000-rs/

    ReplyDelete

Note: Only a member of this blog may post a comment.