代码之家  ›  专栏  ›  技术社区  ›  CodeThing

警告消息:会话\u start():读取会话数据失败:用户(路径:)

  •  0
  • CodeThing  · 技术社区  · 7 年前

    我正在尝试使用Docker设置现有项目。该项目位于codeigniter中,并使用memcached作为驱动程序来设置会话。

    我创建了一个Docker环境 php:7.1.8-apache 并安装了所有必要的软件包。

    Warning Message: session_start(): Failed to read session data: user (path: localhost:11211:128)

    我在互联网上搜索了很多,尝试了很多东西,但都没有效果。

    我有一个档案在里面 application/libraries/Session/drivers/Session_memcached_driver.php

    这是产生错误的代码片段,但我不确定它到底是什么。

    public function read($session_id)
        {
            if (isset($this->_memcached) && $this->_get_lock($session_id))
            {
                // Needed by write() to detect session_regenerate_id() calls
                $this->_session_id = $session_id;
    
                $session_data = (string) $this->_memcached->get($this->_key_prefix.$session_id);
                $this->_fingerprint = md5($session_data);
                return $session_data;
            }
    
            return $this->_fail();
        }
    

    以下是我的Docker配置:

    FROM php:7.1.8-apache
    
    # AUTHOR
    MAINTAINER Development
    
    # INSTALLING PACKAGES
    RUN apt-get update && apt-get install -y \
        git \
        pkg-config \
        build-essential \
        libmemcached-dev \
        libmemcached-tools \
        libicu-dev \
        libmcrypt-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libfreetype6 \
        libfontconfig \
        libxml2-dev \
        vim \
        nano \
        mysql-client \
        libldap2-dev \
        wget
    
    RUN apt-get clean
    
    # Extension PHP
    RUN docker-php-ext-install pdo pdo_mysql
    RUN docker-php-ext-install intl
    RUN docker-php-ext-install mbstring
    RUN docker-php-ext-install bcmath
    RUN docker-php-ext-install mcrypt
    RUN docker-php-ext-install zip
    RUN docker-php-ext-install exif
    RUN docker-php-ext-install soap
    RUN docker-php-ext-install opcache
    RUN docker-php-ext-install iconv
    RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
    RUN docker-php-ext-install gd
    RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
    
    # APCu
    RUN pecl channel-update pecl.php.net
    RUN pecl install apcu
    RUN echo "extension=apcu.so" > /usr/local/etc/php/conf.d/apcu.ini
    
    # Enable PHP 7
    RUN a2enmod rewrite && a2enmod headers && a2enmod expires
    RUN a2enmod php7
    RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
    
    # SETUP VIRTUAL HOST
    COPY .docker/sites-available/default-vhost.conf /etc/apache2/sites-available/default-vhost.conf
    COPY .docker/sites-available/my-vhost.conf /etc/apache2/sites-available/my-vhost.conf
    RUN a2dissite 000-default.conf
    RUN a2ensite default-vhost.conf
    RUN a2ensite my-vhost.conf
    
    # Composer
    RUN curl -sS https://getcomposer.org/installer | php
    RUN mv composer.phar /usr/local/bin/composer
    
    # Memcached
    RUN apt-get update
    RUN apt-get install -y pkg-config build-essential libmemcached-dev
    RUN git clone https://github.com/php-memcached-dev/php-memcached.git
    RUN cd php-memcached && git checkout php7 && phpize && ./configure --disable-memcached-sasl && make && make install
    RUN echo 'extension = memcached.so' > /usr/local/etc/php/conf.d/memcached.ini
    
    # ALIASES
    RUN echo "alias ll='ls -l'" >> /root/.bashrc
    RUN echo "alias la='ls -l'" >> /root/.bashrc
    
    # COPY THE WORKING DIRECTORY
    COPY . /var/www/myproject
    
    # MANAGE DIRECTORY PERMISSIONS
    RUN chown -R www-data:www-data /var/www/myproject
    
    # SERVER RESTART
    RUN service apache2 restart
    

    这是 docker-compose.yml 设置

    version: '3'
    
    services:
      app:
        build:
          context: .
          dockerfile: .docker/Dockerfile
        container_name: gaz-container
        image: gaz-docker
        ports:
          - "80:80"
        volumes:
          - .:/var/www/gaz
        links:
          - memcached:memcached
          - mysql:mysql
    
      memcached:
        image: memcached
        ports:
          - "11211:11211"
    
      mysql:
        container_name: mysql
        image: mysql:5.6
        ports:
          - "3306:3306"
        environment:
          - MYSQL_ROOT_PASSWORD=password
    

    谁能告诉我这里有什么问题吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   CodeThing    7 年前

    天啊。

    幸亏 杜克博迪 . 这篇文章帮助我得到了关于我做错了什么的提示。 https://stackoverflow.com/a/27657937/4342075

    问题是我实际上正在创建多个docker容器,正如您在中的问题中所看到的 docker-compose.yml 文件其中之一就是 memcached . 我试图在主容器中使用memcached,它是 app .

    localhost:11211

    我刚换了衣服

    $config['sess_save_path'] = 'localhost:11211:128'

    $config['sess_save_path'] = 'memcached:11211';

    猜猜它是怎么工作的!!!