質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

FuelPHP

FuelPHPは、軽量高速で開発が可能なPHPのWebアプリケーションフレームワークです。

Q&A

0回答

503閲覧

【FuelPHP】アクセスが集中するときにFatal Errorになる

Sfidante

総合スコア90

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

FuelPHP

FuelPHPは、軽量高速で開発が可能なPHPのWebアプリケーションフレームワークです。

0グッド

1クリップ

投稿2019/03/29 07:29

編集2019/03/29 08:07

構成

  • FuelPHP 1.7
  • PHP 5.6

  • Apache 2.4
  • EC2(2台構成)
  • ELB(Classic)

現象

アクセスが集中すると、下記のFatal Errorが時々起こります

Fatal error: Class 'RequestException' not found in fuel/core/classes/request/driver.php on line 6

このdriver.phpの6行目は下記の部分です。

php

1<?php 2 3namespace Fuel\Core; 4 5class RequestException extends \HttpNotFoundException {} 6class RequestStatusException extends \RequestException {} // ここが6行目 7 8abstract class Request_Driver 9{ 10 // ... 11}

RequestExceptionは以下のとおりです。

php

1<?php 2namespace GuzzleHttp\Exception; 3 4use Psr\Http\Message\RequestInterface; 5use Psr\Http\Message\ResponseInterface; 6use GuzzleHttp\Promise\PromiseInterface; 7use Psr\Http\Message\UriInterface; 8 9/** 10 * HTTP Request exception 11 */ 12class RequestException extends TransferException 13{ 14 /** @var RequestInterface */ 15 private $request; 16 17 /** @var ResponseInterface */ 18 private $response; 19 20 /** @var array */ 21 private $handlerContext; 22 23 public function __construct( 24 $message, 25 RequestInterface $request, 26 ResponseInterface $response = null, 27 \Exception $previous = null, 28 array $handlerContext = [] 29 ) { 30 // Set the code of the exception if the response is set and not future. 31 $code = $response && !($response instanceof PromiseInterface) 32 ? $response->getStatusCode() 33 : 0; 34 parent::__construct($message, $code, $previous); 35 $this->request = $request; 36 $this->response = $response; 37 $this->handlerContext = $handlerContext; 38 } 39 40 /** 41 * Wrap non-RequestExceptions with a RequestException 42 * 43 * @param RequestInterface $request 44 * @param \Exception $e 45 * 46 * @return RequestException 47 */ 48 public static function wrapException(RequestInterface $request, \Exception $e) 49 { 50 return $e instanceof RequestException 51 ? $e 52 : new RequestException($e->getMessage(), $request, null, $e); 53 } 54 55 /** 56 * Factory method to create a new exception with a normalized error message 57 * 58 * @param RequestInterface $request Request 59 * @param ResponseInterface $response Response received 60 * @param \Exception $previous Previous exception 61 * @param array $ctx Optional handler context. 62 * 63 * @return self 64 */ 65 public static function create( 66 RequestInterface $request, 67 ResponseInterface $response = null, 68 \Exception $previous = null, 69 array $ctx = [] 70 ) { 71 if (!$response) { 72 return new self( 73 'Error completing request', 74 $request, 75 null, 76 $previous, 77 $ctx 78 ); 79 } 80 81 $level = (int) floor($response->getStatusCode() / 100); 82 if ($level === 4) { 83 $label = 'Client error'; 84 $className = ClientException::class; 85 } elseif ($level === 5) { 86 $label = 'Server error'; 87 $className = ServerException::class; 88 } else { 89 $label = 'Unsuccessful request'; 90 $className = __CLASS__; 91 } 92 93 $uri = $request->getUri(); 94 $uri = static::obfuscateUri($uri); 95 96 // Client Error: `GET /` resulted in a `404 Not Found` response: 97 // <html> ... (truncated) 98 $message = sprintf( 99 '%s: `%s %s` resulted in a `%s %s` response', 100 $label, 101 $request->getMethod(), 102 $uri, 103 $response->getStatusCode(), 104 $response->getReasonPhrase() 105 ); 106 107 $summary = static::getResponseBodySummary($response); 108 109 if ($summary !== null) { 110 $message .= ":\n{$summary}\n"; 111 } 112 113 return new $className($message, $request, $response, $previous, $ctx); 114 } 115 116 /** 117 * Get a short summary of the response 118 * 119 * Will return `null` if the response is not printable. 120 * 121 * @param ResponseInterface $response 122 * 123 * @return string|null 124 */ 125 public static function getResponseBodySummary(ResponseInterface $response) 126 { 127 $body = $response->getBody(); 128 129 if (!$body->isSeekable() || !$body->isReadable()) { 130 return null; 131 } 132 133 $size = $body->getSize(); 134 135 if ($size === 0) { 136 return null; 137 } 138 139 $summary = $body->read(120); 140 $body->rewind(); 141 142 if ($size > 120) { 143 $summary .= ' (truncated...)'; 144 } 145 146 // Matches any printable character, including unicode characters: 147 // letters, marks, numbers, punctuation, spacing, and separators. 148 if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/', $summary)) { 149 return null; 150 } 151 152 return $summary; 153 } 154 155 /** 156 * Obfuscates URI if there is an username and a password present 157 * 158 * @param UriInterface $uri 159 * 160 * @return UriInterface 161 */ 162 private static function obfuscateUri($uri) 163 { 164 $userInfo = $uri->getUserInfo(); 165 166 if (false !== ($pos = strpos($userInfo, ':'))) { 167 return $uri->withUserInfo(substr($userInfo, 0, $pos), '***'); 168 } 169 170 return $uri; 171 } 172 173 /** 174 * Get the request that caused the exception 175 * 176 * @return RequestInterface 177 */ 178 public function getRequest() 179 { 180 return $this->request; 181 } 182 183 /** 184 * Get the associated response 185 * 186 * @return ResponseInterface|null 187 */ 188 public function getResponse() 189 { 190 return $this->response; 191 } 192 193 /** 194 * Check if a response was received 195 * 196 * @return bool 197 */ 198 public function hasResponse() 199 { 200 return $this->response !== null; 201 } 202 203 /** 204 * Get contextual information about the error from the underlying handler. 205 * 206 * The contents of this array will vary depending on which handler you are 207 * using. It may also be just an empty array. Relying on this data will 208 * couple you to a specific handler, but can give more debug information 209 * when needed. 210 * 211 * @return array 212 */ 213 public function getHandlerContext() 214 { 215 return $this->handlerContext; 216 } 217}

※ 現在は、Apache等でアクセス制御はかけていないです

原因

結論、原因はわかっておりません。

表題では アクセスが集中するとき と記載しましたが、
アクセスが集中しているときに起きている確率が高いということです。
このエラーが起きる頻度は定期ではなく不定期です。

知りたいこと

  1. どのような原因で起きるのか知りたいです。
  2. どのように解消するのがベストなのか知りたいです(アプリケーション側で解消できるのか、Apacheでアクセス制御をした方がよいのか)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

FKM

2019/03/29 07:41

RequestExceptionクラスのソースの提示お願いします。
ssasaki

2019/03/29 08:02

php-fpmは使っていますか?
Sfidante

2019/03/29 08:07

> FKMさん RequestExceptionのソースを記載いたしました。 よろしくお願いいたします。
Sfidante

2019/03/29 08:11

> ssasakiさん 利用されていなそうです
退会済みユーザー

退会済みユーザー

2019/03/29 13:49

日本語的に嫌な名前のFWだけど、 各PHPのクラスファイルで use って必要じゃなかったけ? (バグが)Fuel(ふえる)PHP
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問