bcache を有効後 advanced-cache.php でシンタックスエラー

TOP Forums バグ報告と提案(Requests and Feedback) bcache を有効後 advanced-cache.php でシンタックスエラー

bcache を有効後 advanced-cache.php でシンタックスエラー

Viewing 7 reply threads
  • Author
    Posts
    • #1461
      soybeans59
      Participant

        *環境情報

        kusanagi-docker: 1.6.2
        WP KUSANAGI: 1.2.6←おそらく最新?新規でKRoDで立ち上げた時に手に入ったKusanagiプラグインを使っています
        KUSANAGI Configure: 0.7
        ロードバランサーのは以下に配置したワードプレスは負荷状況に応じてスケールします
        wp-config.php に define(‘WP_CACHE’, true); を追記済

        *本題
        bcache 有効後は正常に動作していますが、突然 advanced-cache.php が後述するコードになり、シンタックスエラーが発生し、ワードプレスへのアクセスが不可となります。
        他のキャッシュ系のプラグインはインストールしておりません。

        対処方法があればアドバイスをいただけると助かります。

        • This topic was modified 6 days, 18 hours ago by soybeans59.
      • #1463
        soybeans59
        Participant
          <?php
          if ( ! defined( 'ABSPATH' ) ) { exit; }
          if ( is_admin() ) { return; }
          
          class SiteManagerAdvancedCache {
          	private $device_regexes = array(
          		'smart' => '/\(iPhone|\(iPod|Android .+ Mobile|IEMobile|Windows Phone|Android; Mobile; .+Firefox/',
          		'tablet' => '/\(iPad| Android |Android; Tablet; .+Firefox/',
          
          	);
          	private $sites = array(
          
          	);
          	private $allowed_query_keys;
          	private $site_mode = false;
          	private $theme_switcher_disabled = false;
          	private $replace_class_file;
          
          	function __construct() {
          		global $table_prefix;
          		$this->replace_class_file = WP_CONTENT_DIR . '/replace-class.php';
          		if ( ! isset( $_SERVER['REQUEST_URI'] ) || ! isset( $_SERVER['HTTP_USER_AGENT'] ) || ! isset( $_SERVER['REQUEST_METHOD'] ) || ! isset( $_SERVER['SCRIPT_NAME'] ) || ! isset( $_SERVER['SERVER_NAME'] ) ) { return; }
          		if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] != 'GET' ) { return; }
          		if ( defined( 'CACHE_EXCLUDE_IP' ) ) {
          			$exclude_ips = explode( '|', CACHE_EXCLUDE_IP );
          			foreach ( $exclude_ips as $exclude_ip ) {
          				if ( $_SERVER['REMOTE_ADDR'] == $exclude_ip || preg_match( '/' . preg_quote( $exclude_ip ) . '/', $_SERVER['REMOTE_ADDR'] ) ) {
          					return;
          				}
          			}
          		}
          		if ( defined( 'CACHE_EXCLUDE_GET' ) && isset( $_GET[CACHE_EXCLUDE_GET] ) ) {
          			return;
          		}
          		foreach ( array_keys( $_COOKIE ) as $key ) {
          			if ( strpos( $key, 'wordpress_logged_in_' ) === 0 || strpos( $key, 'comment_author_' ) === 0 ) {
          				return;
          			}
          		}
          		$this->allowed_query_keys = array( 'm','p','posts','w','cat',略 );
          
          		switch ( $this->site_mode ) {
          		case 'domain' :
          			$add_prefix = isset( $this->sites[$_SERVER['SERVER_NAME']] ) && $this->sites[$_SERVER['SERVER_NAME']] != 1 ? $this->sites[$_SERVER['SERVER_NAME']] . '_' : '';
          			$site_id = isset( $this->sites[$_SERVER['SERVER_NAME']] ) ? $this->sites[$_SERVER['SERVER_NAME']] : '';
          			$table = $table_prefix . $add_prefix;
          			$this->replace_class_file = WP_CONTENT_DIR . '/replace-class-' . $site_id . '.php';
          			break;
          		case 'directory' :
          			$key = '/';
          			if ( trim( $_SERVER['REQUEST_URI'], '/' ) ) {
          				$dirs = explode( '/', trim( $_SERVER['REQUEST_URI'], '/' ), 2 );
          				$key .= array_shift( $dirs ) . '/';
          				unset( $dirs );
          			}
          			$add_prefix = isset( $this->sites[$key] ) && $this->sites[$key] != 1 ? $this->sites[$key] . '_' : '';
          			$site_id = isset( $this->sites[$key] ) ? $this->sites[$key] : BLOG_ID_CURRENT_SITE;
          			$table = $table_prefix . $add_prefix;
          			$this->replace_class_file = WP_CONTENT_DIR . '/replace-class-' . $site_id . '.php';
          			break;
          		default :
          			$table = $table_prefix;
          			$site_id = '';
          		}
          
          		if ( $this->theme_switcher_disabled || ( ! $group = $this->get_device_group() ) ) {
          			$group = '';
          		}
          		if ( ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) || ( isset( $_SERVER['X-Forwarded-Proto'] ) && $_SERVER['X-Forwarded-Proto'] == 'https' ) ) {
          			$protocol = 'https';
          		} else {
          			$protocol = 'http';
          		}
          
          		$requerst_query = '';
          		$request_uri = parse_url( $_SERVER['REQUEST_URI'] );
          		if ( isset( $request_uri['query'] ) ) {
          			parse_str( $request_uri['query'], $requerst_query );
          
          			foreach ( $requerst_query as $key => $var ) {
          				if ( ! in_array( $key, $this->allowed_query_keys ) ) {
          					unset( $requerst_query[$key] );
          				}
          			}
          			ksort( $requerst_query );
          			$requerst_query = http_build_query( $requerst_query );
          		}
          
          		if ( $requerst_query ) {
          			$request_uri = $request_uri['path'] . '?' . $requerst_query;
          		} else {
          			$request_uri = $request_uri['path'];
          		}
          
          		$device_url = array(
          			$group,
          			$protocol,
          			$_SERVER['SERVER_NAME'],
          			$request_uri
          		);
          		$device_url = implode( '|', $device_url );
          		$hash = md5( $device_url );
          
          		$now = date( 'Y-m-d H:i:s' );
          		$expire = date ( 'Y-m-d H:i:s', time() - 30 );
          
          		if ( defined( 'CACHE_DB_NAME' ) && defined( 'CACHE_DB_USER' ) && defined( 'CACHE_DB_PASSWORD' ) && defined( 'CACHE_DB_HOST' ) ) {
          			$dbset = array(
          				'host' => CACHE_DB_HOST,
          				'user' => CACHE_DB_USER,
          				'pass' => CACHE_DB_PASSWORD,
          				'name' => CACHE_DB_NAME
          
          			);
          		} else {
          			$dbset = array(
          				'host' => DB_HOST,
          				'user' => DB_USER,
          				'pass' => DB_PASSWORD,
          				'name' => DB_NAME
          
          			);
          		}
          
          		$dbh = mysqli_connect(
          			$dbset['host'],
          			$dbset['user'],
          			$dbset['pass'],
          			$dbset['name']
          		);
          		if ( false === $dbh ) { return; }
          		if ( function_exists( 'mysqli_set_charset' ) ) {
          			mysqli_set_charset( $dbh, DB_CHARSET );
          		} else {
          			$sql = 'set names ' . DB_CHARSET;
          			mysqli_query( $dbh, $sql );
          		}
          		mysqli_select_db( $dbh, $dbset['name'] );
          
          		$sql = "
          SELECT	*
          FROM	{$table}site_cache
          WHERE	<code>hash</code> = '$hash'
          AND		<code>expire_time</code> >= '$expire'
          ";
          		$ret = mysqli_query( $dbh, $sql );
          
          		if ( $ret ) {
          			while ( $row = mysqli_fetch_object( $ret ) ) {
          				if ( $row->device_url == $device_url && ( strpos( $row->content, '<!-- page cached by KUSANAGI. ' ) !== false || strpos( $row->content, '<!-- page cached by WP SiteManager. ' ) !== false ) ) {
          					if ( $row->expire_time < $now ) {
          						if ( ! $row->updating ) {
          							$sql = "
          UPDATE  {$table}site_cache
          SET     <code>updating</code> = 1
          WHERE   <code>hash</code> = '$hash'
          AND     <code>type</code> = '{$row->type}'
          AND     <code>expire_time</code> = '{$row->expire_time}'
          ";
          							mysqli_query( $dbh, $sql );
          							break;
          						}
          					}
          					$headers = unserialize( $row->headers );
          					if ( $headers ) {
          						foreach ( $headers as $key => $header ) {
          							header( $key . ': ' . $header );
          						}
          					}
          					if ( $row->updating ) {
          						header( 'Cache-Control: no-cache' );
          						header( 'X-B-Cache: updating' );
          					} else {
          						header( 'X-B-Cache: cache' );
          					}
          					if ( file_exists( $this->replace_class_file ) ) {
          						require_once( $this->replace_class_file );
          						$row->content = KUSANAGI_Replace::replace( $row->content );
          					}
          
          					if ( 'rest_api' == $row->type ) {
          						header( 'X-cache-ID: ' . $row->hash );
          						echo $row->content;
          					} else {
          						echo $row->content;
          						echo "\n" .'<!-- CacheID : ' . $row->hash . ' -->';
          					}
          					exit;
          				}
          			}
          		}
          		mysqli_close( $dbh );
          	}
          
          	function get_device_group() {
          		$path = preg_replace( '#^' . str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] ) . '#', '', str_replace( '\\', '/', ABSPATH ) );
          
          		if ( isset( $_GET['site-view'] ) ) {
          			if ( strtolower( $_GET['site-view'] ) == 'pc' ) {
          				setcookie( 'site-view', 'pc', 0, $path );
          				return false;
          			}
          			foreach ( $this->device_regexes as $group => $regex ) {
          				if ( strtolower( $_GET['site-view'] ) == strtolower( $group ) ) {
          					setcookie( 'site-view', $group, 0, $path );
          					return $group;
          				}
          			}
          		} elseif ( isset( $_COOKIE['site-view'] ) ) {
          			if ( strtolower( $_COOKIE['site-view'] ) == 'pc' ) {
          				setcookie( 'site-view', 'pc', 0, $path );
          				return false;
          			}
          			foreach ( $this->device_regexes as $group => $regex ) {
          				if ( strtolower( $_COOKIE['site-view'] ) == strtolower( $group ) ) {
          					setcookie( 'site-view', $group, 0, $path );
          					return $group;
          				}
          			}
          		}
          
          		foreach ( $this->device_regexes as $group => $regex ) {
          			if ( preg_match( $regex, $_SERVER['HTTP_USER_AGENT'] ) ) {
          				return $group;
          			}
          		}
          		return false;
          	}
          }
          new SiteManagerAdvancedCache();
          		foreach ( $this->device_regexes as $group => $regex ) {
          			if ( preg_match( $regex, $_SERVER['HTTP_USER_AGENT'] ) ) {
          				return $group;
          			}
          		}
          		return false;
          	}
          }
          new SiteManagerAdvancedCache();
        • #1465
          yosuke
          Participant

            soybeans59 さん、こんちにわ。

            まず、トップページにありますように、kusanagi status の結果の貼り付けをお願い致します。
            また、ご使用のWebサービス(httpd or nginx)の error.log の内容も貼り付けをお願い致します。
            (「シンタックスエラーが発生し」のエラー内容を確認したいです。)

          • #1470
            soybeans59
            Participant

              yosuke 様、ご連絡ありがとうございます。
              提供情報が不足しており申し訳ございません。

              エラーログとKusanagiの情報などを共有いたします。

              $ kusanagi-docker status
                    Name                    Command                  State                                                  Ports                                            
              ---------------------------------------------------------------------------------------------------------------------------------------------------------------
              wordpress_config   docker-entrypoint.sh wp -- ...   Restarting                                                                                                 
              wordpress_ftp      /bin/sh -c /docker-entrypo ...   Up                                                                                                         
              wordpress_httpd    /docker-entrypoint.sh /usr ...   Up (healthy)   0.0.0.0:80->80/tcp,:::80->80/tcp, 8080/tcp, 0.0.0.0:443->8443/tcp,:::443->8443/tcp, 8443/udp
              wordpress_php      /usr/local/bin/docker-entr ...   Up (healthy)                                                                                               
              INFO: Done.
              $ kusanagi-docker --version
              1.6.2
              INFO: Done.

              nginxコンテナ
              以下のような500エラーを吐いております。
              {"log":"10.0.31.196 - - [07/Nov/2024:04:38:23 +0000] \"GET / HTTP/1.1\" 500

              phpコンテナ
              シンタックスエラーの情報です

              {"log":"[07-Nov-2024 04:38:30 UTC] PHP Parse error:  syntax error, unexpected '}', expecting end of file in /home/kusanagi/wordpress/DocumentRoot/wp-content/advanced-cache.php on line 239\n","stream":"stderr","time":"2024-11-07T04:38:30.062941601Z"}
              {"log":"[07-Nov-2024 04:38:30 UTC] PHP Parse error:  syntax error, unexpected '}', expecting end of file in /home/kusanagi/wordpress/DocumentRoot/wp-content/advanced-cache.php on line 239\n","stream":"stderr","time":"2024-11-07T04:38:30.269020456Z"}
              {"log":"[07-Nov-2024 04:38:31 UTC] PHP Parse error:  syntax error, unexpected '}', expecting end of file in /home/kusanagi/wordpress/DocumentRoot/wp-content/advanced-cache.php on line 239\n","stream":"stderr","time":"2024-11-07T04:38:31.159448671Z"}
              {"log":"[07-Nov-2024 04:38:31 UTC] PHP Parse error:  syntax error, unexpected '}', expecting end of file in /home/kusanagi/wordpress/DocumentRoot/wp-content/advanced-cache.php on line 239\n","stream":"stderr","time":"2024-11-07T04:38:31.516737511Z"}
              {"log":"[07-Nov-2024 04:38:34 UTC] PHP Parse error:  syntax error, unexpected '}', expecting end of file in /home/kusanagi/wordpress/DocumentRoot/wp-content/advanced-cache.php on line 239\n","stream":"stderr","time":"2024-11-07T04:38:34.180800412Z"}

              また、頻繁に advanced-cache.php ファイルの書き換えが行われていることも確認しております。

              • This reply was modified 3 days, 2 hours ago by soybeans59.
            • #1472
              satoru
              Moderator

                KUSANAGI Runs on Docker(RoD) に含まれるWordPress用プラグインが古い事がわかりました。
                RoD の 1.6.5 を先日リリースし、プラグインを最新のものに変更しました。
                プラグイン自体の更新コマンドはございません。更新するには、以下のファイルをDocker環境の wp-content へコピーしていただければと思います。

                $HOME/.kusanagi/lib/mu-plugins/

                上記ファイル更新後、現象が再発するようであれば、ご連絡お願いします。

              • #1473
                soybeans59
                Participant

                  satoru 様

                  ご連絡ありがとうございます。
                  KRoDがバージョンアップされていることを確認し、新しいバージョンのKusanagiプラグインを取得できました。

                  新しいバージョンで検証させていただきます。

                • #1474
                  soybeans59
                  Participant

                    追加の質問なのですが、advanced-cache.php というファイルは頻繁に書き換えが行われるファイルなのでしょうか?
                    もしその場合、どこで書き換え処理(ファイルの更新)が行われているのか教えていただけると助かります。

                  • #1475
                    soybeans59
                    Participant

                      追加情報です。

                      下記のエラーログをPHPコンテナで確認しております。繰り返し以下のログが出ている状況です。上記のシンタックスエラーと関係はございますか?

                      [13-Nov-2024 01:49:01 UTC] WordPress database error Incorrect database name ” for query SHOW TABLES FROM LIKE ‘wp_site_cache’ made by KUSANAGI_Page_Cache::create_cache_table
                      [13-Nov-2024 01:49:01 UTC] WordPress database error Table ‘wp_site_cache’ already exists for query
                      CREATE TABLE wp_site_cache (
                      id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
                      hash varchar(32) NOT NULL,
                      content longtext NOT NULL,
                      device_url text NOT NULL,
                      type varchar(20) NOT NULL,
                      post_type varchar(200) NOT NULL,
                      headers text NOT NULL,
                      user_agent text NOT NULL,
                      server varchar(16) NOT NULL,
                      updating tinyint(1) NOT NULL DEFAULT ‘0’,
                      create_time datetime NOT NULL,
                      expire_time datetime NOT NULL,
                      PRIMARY KEY (id),
                      KEY hash (hash),
                      KEY expire_time (expire_time),
                      KEY type (type,post_type),
                      KEY updating (updating)
                      ) DEFAULT CHARACTER SET utf8mb4 made by KUSANAGI_Page_Cache::create_cache_table
                      [13-Nov-2024 01:49:01 UTC] WordPress database error Incorrect database name ” for query SHOW TABLES FROM LIKE ‘wp_site_cache’ made by KUSANAGI_Page_Cache::create_cache_table
                      [13-Nov-2024 01:49:02 UTC] WordPress database error Table ‘wp_site_cache’ already exists for query
                      CREATE TABLE wp_site_cache (
                      id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
                      hash varchar(32) NOT NULL,
                      content longtext NOT NULL,
                      device_url text NOT NULL,
                      type varchar(20) NOT NULL,
                      post_type varchar(200) NOT NULL,
                      headers text NOT NULL,
                      user_agent text NOT NULL,
                      server varchar(16) NOT NULL,
                      updating tinyint(1) NOT NULL DEFAULT ‘0’,
                      create_time datetime NOT NULL,
                      expire_time datetime NOT NULL,
                      PRIMARY KEY (id),
                      KEY hash (hash),
                      KEY expire_time (expire_time),
                      KEY type (type,post_type),
                      KEY updating (updating)
                      ) DEFAULT CHARACTER SET utf8mb4 made by KUSANAGI_Page_Cache::create_cache_table

                      • This reply was modified 23 hours, 34 minutes ago by soybeans59.
                      • This reply was modified 23 hours, 34 minutes ago by soybeans59.
                  Viewing 7 reply threads
                  • You must be logged in to reply to this topic.

                  Next article

                  フォーラムについて