Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Commit

Permalink
Create an example with Docker to show websupport-sk/pecl-memcache#23
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Aug 17, 2017
0 parents commit 29d5b3e
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# pecl-memcache Issue #23

This repository reproduces the issue described in
[websupport-sk/pecl-memcache#23][pecl-memcache-23].

In short, on PHP 7.1, when using `memcache` as the `session.save_handler`, the
following warning occurs when calling `session_start()`:

```
Warning: session_start(): Failed to read session data: memcache (path: tcp://127.0.0.1:11211)
```

The same code and settings does not result in this warning on PHP 7.0.


## Running the Example

This example uses [Docker][] and [Docker Compose][] to build two images and run
two containers (one for PHP 7.0 and one for PHP 7.1). Both are identical, expect
for the version of PHP used.

``` bash
git clone /~https://github.com/ramsey/pecl-memcache-issue-23
cd pecl-memcache-issue-23/
docker-compose up
```

Now, the two containers should be running, you can open the following in your
browser to verify:

* <http://localhost:8001/info.php> (should be running PHP 7.0)
* <http://localhost:8002/info.php> (should be running PHP 7.1)

To test the `session_start()` issue and see the warning, open the following:

* PHP 7.0: <http://localhost:8001/> (the session should work as expected)
* PHP 7.1: <http://localhost:8002/> (`session_start()` should generate a warning)


[pecl-memcache-23]: /~https://github.com/websupport-sk/pecl-memcache/issues/23
[docker]: https://docs.docker.com/
[docker compose]: https://docs.docker.com/compose/overview/
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'
services:
php70:
build:
context: ./docker
dockerfile: Dockerfile
args:
php_version: "7.0"
image: pecl-memcache-issue-23:php70
ports:
- "8001:8000"
volumes:
- .:/code
php71:
build:
context: ./docker
dockerfile: Dockerfile
args:
php_version: "7.1"
image: pecl-memcache-issue-23:php71
ports:
- "8002:8000"
volumes:
- .:/code
13 changes: 13 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG php_version=latest
FROM php:${php_version}

COPY docker-setup.sh docker-entrypoint /usr/local/bin/
COPY memcache.ini /usr/local/etc/php/conf.d/

RUN /usr/local/bin/docker-setup.sh \
&& rm /usr/local/bin/docker-setup.sh

WORKDIR /code
EXPOSE 8000

ENTRYPOINT ["docker-entrypoint"]
4 changes: 4 additions & 0 deletions docker/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
/usr/bin/memcached -m 50 -p 11211 -u memcached -l 127.0.0.1 -d
php -S 0.0.0.0:8000 -t /code/
21 changes: 21 additions & 0 deletions docker/docker-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

apt-get -y update
apt-get -y install memcached zlib1g-dev

groupadd -r memcached && useradd -r -g memcached memcached

mkdir -p /code/pecl-memcache
cd /code

curl -L -o pecl-memcache.tar.gz /~https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.tar.gz
tar --strip-components=1 -C /code/pecl-memcache/ -zxf pecl-memcache.tar.gz

cd /code/pecl-memcache
phpize
./configure
make
make install

cd /code
rm -rf /code/pecl-memcache/ pecl-memcache.tar.gz
3 changes: 3 additions & 0 deletions docker/memcache.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extension = memcache.so
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"
19 changes: 19 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
session_start();

$_SESSION['foo'] = 'bar';

?>

<h1>Hello!</h1>

<p>I just stored some data to the session.</p>

<p><a href="next.php">Go to the next page to read data from the session.</a></p>

<ul>
<li><code>PHP version: <?php echo phpversion(); ?></code></li>
<li><code>pecl/memcache version: <?php echo phpversion('memcache'); ?></code></li>
<li><code>session.save_handler = <?php echo ini_get('session.save_handler'); ?></code></li>
<li><code>session.save_path = <?php echo ini_get('session.save_path'); ?></code></li>
</ul>
2 changes: 2 additions & 0 deletions info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
phpinfo();
8 changes: 8 additions & 0 deletions next.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
session_start();

header('Content-Type: text/plain');

echo '$_SESSION = ' . "\n\n";

var_export($_SESSION);

0 comments on commit 29d5b3e

Please sign in to comment.