0

我正在使用 laravel 8。在升级到 octane 之前,我在 $_SERVER['REMOTE_ADDR'] 中获取了 IP 地址。更改为辛烷值后,$_SERVER 中没有此类索引。

我在注册控制器的验证器中使用此变量,而新用户正在注册应用程序。

 protected function validator(array $data)
      {
 dd($_SERVER['REMOTE_ADDR'])
}

当我转储 $_SERVER 时,我得到了这个数组(我正在隐藏应用程序详细信息。)

  "LARAVEL_OCTANE" =>"1"
  "APP_BASE_PATH" => "xxx"
  "JOURNAL_STREAM" => "xxx"
  "PATH" =>"xxx"
  "INVOCATION_ID" => "xxx"
  "LANG" => "xxx"
  "SUPERVISOR_ENABLED" =>"xxx"
  "SUPERVISOR_SERVER_URL" => "xxx"
  "SUPERVISOR_PROCESS_NAME" =>"xxx"
  "APP_ENV" => "xxx"
  "PWD" => "xxx"
  "PHP_SELF" => "xxx"
  "SCRIPT_NAME" => "xxx"
  "SCRIPT_FILENAME" =>"xxx"
  "PATH_TRANSLATED" => "xxx"
  "DOCUMENT_ROOT" => ""
  "REQUEST_TIME_FLOAT" => "xxx"
  "REQUEST_TIME" => "xxx"
  "argv" => array:2 [▶]
  "argc" =>"xxx"
  "APP_NAME" => "xxx"
  "APP_KEY" => "xxx"
  "APP_DEBUG" => "xxx"
  "APP_LOG_LEVEL" => "xxx"
  "APP_URL" => "xxx"
  "OCTANE_SERVER" =>"xxx"
  "LOG_CHANNEL" => "xxx"
  "DB_CONNECTION" => "xxx"
  "DB_HOST" => "xxx"
  "DB_PORT" => "xxx"
  "DB_DATABASE" => "xxx"
  "DB_USERNAME" =>"xxx"
  "DB_PASSWORD" => "xxx"
  "BROADCAST_DRIVER" => "xxx"
  "CACHE_DRIVER" => "xxx"
  "SESSION_DRIVER" => "xxx"
  "SESSION_LIFETIME" => "xxx"
  "QUEUE_CONNECTION" => "xxx"
  ...............
 

4

1 回答 1

1

我已经找到了解决这个问题的方法。正如@Rwd 评论所 $_SERVER['REMOTE_ADDR']取代request()->ip()

它工作正常。(在octane中,初始化请求时不会初始化PHP的全局变量,例如$_SERVER,$_POST,$_Get等。从以下文章中获取详细信息。https://developpaper.com/php -fpm-vs-swoole/ )

于 2021-10-07T10:40:05.530 回答