ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
| この記事の要点 |
|
このエラーの概要
PHP スクリプトが規定時間(既定 30 秒)を超えると即座に終了し、次のメッセージが出ます:
Fatal error: Maximum execution time of 30 seconds exceeded in
/var/www/html/import.php on line 42
これは PHP の安全機構で、無限ループや極端に遅い処理が Web サーバーを占有し続けるのを防ぐためです。バッチ処理 / CSV インポート / 外部 API ループ / 大量画像処理で頻発します。
対処1: php.ini で永続的に変更
# php.ini の場所を確認
php --ini
# Loaded Configuration File: /etc/php/8.2/fpm/php.ini
# 編集
sudo vi /etc/php/8.2/fpm/php.ini; /etc/php/8.2/fpm/php.ini
; 既定 30 秒 → 300 秒(5 分)
max_execution_time = 300
; 0 で無制限(CLI のみ推奨、Web では絶対避ける)
; max_execution_time = 0
; 入力受付の最大時間(POST/GET の読み取り)
max_input_time = 300
; メモリ上限も同時に上げることが多い
memory_limit = 512M
; アップロード関連
upload_max_filesize = 100M
post_max_size = 100M
反映するには PHP-FPM / Apache の再起動が必要:
# Nginx + PHP-FPM
sudo systemctl restart php8.2-fpm
# Apache mod_php
sudo systemctl restart apache2
# 変更確認
php -i | grep max_execution_time
# max_execution_time => 300 => 300
対処2: スクリプト内で一時変更
ini_set('max_execution_time', ...) と set_time_limit(...) の違い:
| 関数 | 動作 |
|---|---|
ini_set('max_execution_time', 300) | 残り時間を 300 にセット、それまでの経過は無視 |
set_time_limit(300) | 同様、明示的・分かりやすい |
ini_set('max_execution_time', 0) | 無制限 |
set_time_limit(0) | 無制限 |
safe_mode 有効時 / 一部の共有レンタルサーバーでは set_time_limit() が無効化されているケースがあります。
対処3: Nginx + PHP-FPM の壁
Nginx + PHP-FPM では php.ini の max_execution_time より先に他のタイムアウトに引っ掛かることがあります:
; /etc/php/8.2/fpm/pool.d/www.conf
; PHP-FPM プロセスを終了するまでの時間
request_terminate_timeout = 300s# /etc/nginx/sites-available/example.conf
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
# FastCGI 応答待ち時間(既定 60s)
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_connect_timeout 75;
}
# サーバー全体
http {
proxy_read_timeout 300;
send_timeout 300;
}
3 箇所すべてを揃える必要があります:
| 設定 | 場所 | 例 |
|---|---|---|
| PHP 実行時間 | php.ini | max_execution_time = 300 |
| PHP-FPM プロセス終了 | www.conf | request_terminate_timeout = 300s |
| Nginx FastCGI 読取 | nginx.conf / vhost | fastcgi_read_timeout 300; |
対処4: Apache mod_php / .htaccess
# .htaccess または httpd.conf
php_value max_execution_time 300
php_value memory_limit 512M
php_value max_input_time 300
# Apache 自体のタイムアウト
Timeout 300
対処5: バッチは CLI で実行
そもそも長時間処理は Web からではなく CLI から動かすのが原則:
# CLI は max_execution_time = 0(無制限)が既定
php /var/www/html/artisan import:csv
# Cron で定期実行
# /etc/cron.d/myapp
0 3 * * * www-data php /var/www/html/artisan schedule:run
# キューワーカー
php artisan queue:work --tries=3 --timeout=600
本質的な対処: 処理を分割
そもそも 30 秒で終わらない Web リクエストは UX 的にも問題。非同期化が王道:
// Laravel ジョブキューに投げる
ImportCsvJob::dispatch($file)->onQueue('imports');
// ユーザーには「処理中」を返してすぐ応答
return response()->json(['status' => 'queued', 'job_id' => $jobId]);
// クライアントはポーリング or WebSocket で完了通知
// /api/jobs/{id}/status
FAQ
Q: set_time_limit(0) を入れたのに 30 秒で死ぬ
A: PHP-FPM の request_terminate_timeout または Nginx の fastcgi_read_timeout に引っ掛かっています。3 つすべてを揃えてください。
Q: max_execution_time は何を測っている?
A: PHP の実行時間のみ。sleep() や system() / exec() で外部コマンド実行中の時間は含みません(OS 依存)。Windows では実時間で測ります。
Q: ループの途中で setting したい
A: set_time_limit(30) をループ内で呼ぶと「ここから 30 秒」のタイマーがリセットされ続け、事実上無制限と同じになります。
関連エラー
Allowed memory size of N bytes exhausted—memory_limit不足、別途対処504 Gateway Time-out— Nginx のタイムアウト、上記設定で対処Maximum execution time exceeded(CLI 上)— CLI でも明示的にmax_execution_timeが設定されている、またはset_time_limitが呼ばれた
ページの作成
親となるページを選択してください。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球
子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール
親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
子ページはありません
- Fatal error: Maximum execution time of 30 seconds exceeded in...
- Fatal error: Uncaught Error: Cannot use object of type stdClass as array in ...
- Warning: Use of undefined constant ... - assumed '...' (this will throw an Error)
- ERROR: Call to undefined method Maatwebsite\Excel\Excel::load()
- Maximum execution time of 30 seconds exceeded
- Your requirements could not be resolved to an installable set of packages. ... To enable extensions, verify that they are enabled in your .ini files:
- could not find driver
- the requested PHP extension mbstring is missing from your system.
- the requested PHP extension dom is missing from your system.
- A non well formed numeric value encountered
- Warning: Cannot modify header information - headers already sent by ...
- php_network_getaddresses: getaddrinfo failed: Name or service not known
- XMLWriter::openUri(): Unable to resolve file path
- Object of class stdClass could not be converted to string
- Class 'Google_Service_Youtube' not found
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript base URL 取得方法|window.location.origin と SSR/Node.js 対応
- 4 YouTube Data API v3 エラー一覧|403/400/404 の主要原因と切り分け
- 5 Spring Frameworkのアノテーション一覧
- 6 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 7 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- Laravel キャッシュクリア完全ガイド(cache:clear / config:clear / 2026-05-18 07:42:07
- プロジェクトの作成と削除 2026-05-18 07:42:07
- インストール直後にNetbeansが反応しない 2026-05-18 07:42:07
- 動画やチャンネルの検索 2026-05-18 07:42:07
- APIキー取得方法 2026-05-18 07:42:07
- チャンネル情報の取得 2026-05-18 07:42:07
- API 入門 — Web API(REST / GraphQL / gRPC / 2026-05-18 07:42:07
- インストール(eclipseプラグイン) 2026-05-18 07:42:07
- Laravel「Dotenv values containing spaces must be surrounded 2026-05-18 07:42:07
- エラー一覧 2026-05-18 07:42:07
- curl: (51) SSL: certificate subject name '~' does not match 2026-05-18 07:42:07
- インストール方法(Windows版) 2026-05-18 07:42:07
- JSONから配列に変換 2026-05-18 07:42:07
- 処理を一定時間待つ 2026-05-18 07:42:07
- A non well formed numeric value encountered 2026-05-18 07:42:07
コメントを削除してもよろしいでしょうか?