awslabs / aws-elasticache-cluster-client-memcached-for-php

Amazon ElastiCache Cluster Client is an enhanced PHP library to connect to ElastiCache clusters. This client library has been built upon libmemcached and is released under the Apache License.
Other
62 stars 33 forks source link

Missing support for PHP7.1 #11

Open carlnordenfelt opened 7 years ago

carlnordenfelt commented 7 years ago

When is support for PHP7.1 expected to arrive?

PHP Warning:  PHP Startup: memcached: Unable to initialize module
Module compiled with module API=20151012
PHP    compiled with module API=20160303
These options need to match in Unknown on line 0

PHP 7.1.0-5+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.0-5+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies

Classic php7.0-dev build I'd guess.

jpriebe commented 7 years ago

We need this, too. We want to hitch our wagon to Elasticache, but we need to know that this module will keep up with PHP releases. Given how long PHP releases are in beta, it shouldn't be too much to ask to have this module updated within a week or two of the release, should it?

jpriebe commented 7 years ago

I opened a support ticket with AWS, and I got this most unhelpful response:

Depending on who picks up this or future cases next, it may be that we are unable to offer assistance as PHP is not a supported application: https://aws.amazon.com/premiumsupport/features/

From our ElastiCache regarding PHP 7.x, we only provide basic installation steps and for the application. As mentioned before, our knowledge with this third party application is limited, so at this time there is nothing else documented on our side. There are also no road-maps in place for this process that I can confirm on my side. For any new features and services at AWS, please keep an eye on 'What's new at AWS'.

My contention is that I'm not looking for support with PHP per se, but I'm looking for support on a client library for PHP that was built and maintained by AWS. Or AWS Labs, anyway.

Pierozi commented 7 years ago

Hello, Try the release beta v2.0b1, it's work for me under php 7.1.1

elyobo commented 7 years ago

https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/commit/b55106b26b78907a1b2b6b9813e645c7fe978ffc looks promising

malyeyev-AMZN commented 7 years ago

We have just recently merged most recent fixes from the upstream. Please make sure you are using the latest v2.0.1 release: https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/releases/tag/v2.0.1

carlnordenfelt commented 7 years ago

Thanks for the update!

sodabrew commented 7 years ago

@malyeyev-AMZN The file on S3 at ClusterClient/PHP-7.0/latest-64bit only includes a PHP 7.0 build. I don't see a corresponding download at ClusterClient/PHP-7.1/latest-64bit built for PHP 7.1. Note that the PHP API version was updated and extensions must be recompiled.

jpriebe commented 7 years ago

Please release a binary compiled against the PHP 7.1 API. My attempts to build this thing myself have so far been disastrous.

jpriebe commented 7 years ago

@Pierozi - how did you get this to work with PHP 7.1.1? Did you compile it yourself? I had problems with the recent upstream merge that I thought I was able to work around, but then I ran into this issue:

libmemcached.so.10: cannot open shared object file: No such file or directory in Unknown on line 0

malyeyev-AMZN commented 7 years ago

@jpriebe: if you could provide what kind of Linux you're trying to compile it on and exact steps and commands you're using, we might be able to help

malyeyev-AMZN commented 7 years ago

These steps worked for me on Ubuntu 16.04 AMI (ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170113 (ami-6edd3078))

# Install PHP 7.1
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1

# Build ElastiCache libmemcached
git clone https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached.git
cd aws-elasticache-cluster-client-libmemcached
sudo apt-get install -y gcc g++ make 
./configure --prefix=$(pwd)/local --with-pic
make
make install

# Build ElastiCache php-memcached
cd ..
git clone https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php.git -b php7
cd aws-elasticache-cluster-client-memcached-for-php/
sudo apt-get install -y php7.1-dev pkg-config libsasl2-dev
phpize
./configure --with-libmemcached-dir=../aws-elasticache-cluster-client-libmemcached/local/ --disable-memcached-sasl
make
sudo make install
sudo cp ./modules/memcached.so "$(php -r 'echo ini_get("extension_dir");')"
echo "extension=memcached.so" | sudo tee $(dirname "$(php -r 'echo php_ini_scanned_files();' | head -1)")/memcached.ini >/dev/null

# Verify
php -r "echo((extension_loaded('memcached') ? \"Yes\n\" : \"No\n\"));"

Please let me know if this works for you!

malyeyev-AMZN commented 7 years ago

Also, this:

libmemcached.so.10: cannot open shared object file: No such file or directory in Unknown on line 0

makes me think that you compile the library on one host and then copy it to another that does not have ElastiCache libmemcached (or plain libmemcached for that matter) installed.

To statically build in libmemcached into the php module you need to also run this command between .configure ... and make commands in the # Build ElastiCache php-memcached section above.

sed -i "s#-lmemcached\b#../aws-elasticache-cluster-client-libmemcached/local/libmemcached/.libs/libmemcached.a -lcrypt -lpthread -lm -lstdc++ -lsasl2#" Makefile && sed -i "s#-lmemcachedutil\b#../aws-elasticache-cluster-client-libmemcached/local/libmemcached/.libs/libmemcachedutil.a#" Makefile
jpriebe commented 7 years ago

Here's what I did:

#!/bin/sh
####
#### Builds aws-elasticache-cluster-client-memcached-for-php for PHP 7.1 on CentOS 7
#### (libmemcached is statically linked into the module binary)
####
#### assumes your repo is configured to install PHP 7.1 (use Remi's repo!).  Just
#### in case you aren't familiar, here's how you do that:
####
#### ---------------------------------------------------------------------------
#### cd /tmp
#### wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
#### sudo rpm -Uvh remi-release-7.rpm
#### sudo yum-config-manager --enable remi-php71
#### sudo yum install -y php php-cli 
#### ---------------------------------------------------------------------------
####
#### client module build instructions were patterned after this guide:
#### http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Appendix.PHPAutoDiscoveryCompile.html
####

sudo yum install gcc gcc-c++ autoconf libevent-devel php-devel

cd /tmp
mkdir /tmp/libmemcached

git clone https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached.git
cd aws-elasticache-cluster-client-libmemcached

#### roll back to before 1.0.18 upstream was merged; this broke the build
#### https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/issues/8

git checkout fb9a57250aebca26653ff4b294fd2377ae1eb0f1

mkdir BUILD
cd BUILD
../configure --prefix=/tmp/libmemcached --with-pic
make
make install

cd /tmp

git clone https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php.git
cd aws-elasticache-cluster-client-memcached-for-php 
git checkout php7
phpize
./configure --with-libmemcached-dir=/tmp/libmemcached --disable-memcached-sasl
sed -i "s#-lmemcached#/tmp/libmemcached/lib/libmemcached.a -lcrypt -lpthread -lm -lstdc++ -lsasl2#" Makefile
make

cp modules/memcached.so /tmp/amazon-elasticache-cluster-client.so
pabdavis commented 7 years ago

Using a modified version of the script above and AWS Centos 7 ami (ami-6d1c2007) I was able to build a working client. The additional changes to the Makefile prevent the following error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/amazon-elasticache-cluster-client.so' - libmemcachedutil.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Fatal error:  Uncaught Error: Class 'Memcached' not found 
#!/bin/sh
####
#### Builds aws-elasticache-cluster-client-memcached-for-php for PHP 7.1 on CentOS 7
#### (libmemcached is statically linked into the module binary)
####
#### assumes your repo is configured to install PHP 7.1 (use Remi's repo!).  Just
#### in case you aren't familiar, here's how you do that:
####
#### ---------------------------------------------------------------------------
#### cd /tmp
#### wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
#### sudo rpm -Uvh remi-release-7.rpm
#### sudo yum-config-manager --enable remi-php71
#### sudo yum install -y php php-cli
#### ---------------------------------------------------------------------------
####
#### client module build instructions were patterned after this guide:
#### http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Appendix.PHPAutoDiscoveryCompile.html
####

yum -y install epel-release
yum -y update

yum install -y wget git

#### PHP
yum install -y libxslt libpng libXpm fontconfig
cd /tmp
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
yum-config-manager --enable remi-php71

yum install -y php php-cli 
yum install -y gcc gcc-c++ autoconf libevent-devel php-devel zlib-devel

cd /tmp
mkdir /tmp/libmemcached

git clone https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached.git
cd aws-elasticache-cluster-client-libmemcached

#### roll back to before 1.0.18 upstream was merged; this broke the build
#### https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/issues/8

git checkout fb9a57250aebca26653ff4b294fd2377ae1eb0f1

mkdir BUILD
cd BUILD
../configure --prefix=/tmp/libmemcached --with-pic
make
make install

#### sasl2 could not be found without 2nd symlink below
cd /usr/lib64
ln libsasl2.so.3 libsasl2.so.2
ln libsasl2.so.3 libsasl2.so

cd /tmp

git clone https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php.git
cd aws-elasticache-cluster-client-memcached-for-php
git checkout php7
phpize
./configure --with-libmemcached-dir=/tmp/libmemcached --disable-memcached-sasl
sed -i "s#-lmemcached#/tmp/libmemcached/lib/libmemcachedutil.a /tmp/libmemcached/lib/libmemcached.a -lcrypt -lpthread -lm -lstdc++ -lsasl2#" Makefile
sed -i "s#-lmemcachedutil##" Makefile
sed -i "s#-L/tmp/libmemcached/lib##" Makefile
make

cp modules/memcached.so /tmp/amazon-elasticache-cluster-client.so
fenixkim commented 7 years ago

I have not be a able to build it with any of the suggestions appears here, Please release a binary compiled against the PHP 7.1.7 API. This is very frustrating... Is there any other workaround for PHP 7.1.7?

Note: I'm using Beanstalk.

Thanks in advance

BobDankert commented 6 years ago

I am also looking for a PHP 7.1 binary. I tried https://s3.amazonaws.com/elasticache-downloads/ClusterClient/PHP-7.0/latest-64bit, however this fails to install on PHP 7.1 (using Beanstalk, similar to @fenixkim).

@fenixkim - were you able to get this working on an Elastic Beanstalk image?

fenixkim commented 6 years ago

@BobDankert unfortunately not, we really need the binary file for the latest php versions.

For my project, I installed the memcached php module using a .ebextensions config file. So the service will run in each instances created. But this limit to use the autodiscover feature suggested by aws.

I’m not an expert in this, but if you need I can sent the example of my config files. I know that this is very fruatranting, so I really would like to offer you any help.

Let me know

BobDankert commented 6 years ago

I was able to get the cluster client installed using most of the steps listed by @pabdavis. I haven't had a chance to test it yet, but the module is installed in PHP now and I will be running testing later today.

I am using the latest PHP 7.1 EB AMI for my machine, and skipped all of the "yum install" commands that pabdavis listed above, except you do need to run "sudo yum install libevent-devel". Also, make sure to remove the current PHP memcached libraries: "sudo yum remove php71-pecl-memcache.x86_64 php71-pecl-memcached.x86_64". Instead of the ln commands that pabdavis listed, I ran these commands: "ln libsasl2.so.2 libsas12.so.3" and "ln libsasl2.so.2 libsas12.so". I also did not need to run any of the "sed" commands. I ran "make" and "make install" at the end, then added a ini file to "/etc/php-7.1.d" with "extension=memcached.so" in the file, to load the extension. It is now showing

fenixkim commented 6 years ago

Oh, great!!

I’m going to follow your steps ASAP. However if you write here all the commands in the order your uses or the .config file it would be really great!

Many thanks!!

BobDankert commented 6 years ago

I'm working on documenting my steps from beginning to end. I'll post them when I get everything set.

BobDankert commented 6 years ago

Here are the steps I went through on a fresh instance with nothing else done on the instance:

Build based on AMI: aws-elasticbeanstalk-amzn-2017.03.1.x86_64-php71-hvm-201709200829 (ami-c605eabc)

sudo su

yum update
yum install libevent-devel
yum remove php71-pecl-memcache php71-pecl-memcached

mkdir /tmp/libmemcached
cd /tmp/libmemcached
git clone https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached.git
cd aws-elasticache-cluster-client-libmemcached
git checkout fb9a57250aebca26653ff4b294fd2377ae1eb0f1
mkdir BUILD
cd BUILD
../configure --prefix=/tmp/libmemcached --with-pic
make
make install

cd /usr/lib64
ln libsasl2.so.2 libsasl2.so.3
ln libsasl2.so.2 libsasl2.so

cd /tmp
git clone https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php.git
cd aws-elasticache-cluster-client-memcached-for-php/
git checkout php7
phpize
./configure --with-libmemcached-dir=/tmp/libmemcached --disable-memcached-sasl
make
make install

echo extension=memcached.so > /etc/php-7.1.d/50-memcached.ini
php -i | grep memcached

exit

Again, a big thanks to @pabdavis for posting his process to getting it to work on his machine. I still haven't put this live yet and run it through all of the testing - that will take a few days. I'll post if there are any issues with this in our environment.

garrows commented 6 years ago

Instead of messing around and compiling it yourself, here is a version that I made. https://s3.amazonaws.com/php-amazon-elasticache-cluster-client-7-1/amazon-elasticache-cluster-client.so

Should be able to install it with

curl -o amazon-elasticache-cluster-client.so https://s3.amazonaws.com/php-amazon-elasticache-cluster-client-7-1/amazon-elasticache-cluster-client.so
mv amazon-elasticache-cluster-client.so "$(php -r 'echo ini_get("extension_dir");')"

Hope this helps.

sodabrew commented 6 years ago

I've recently released php-memcached 3.0.4 (see https://pecl.php.net/package/memcached/3.0.4), which fixes a memory corruption bug under high load, and supports PHP 7.0, 7.1, and now 7.2 as well. Would be great to see this downstream build available for all three PHP 7.x versions. (PHP 7.2.0 is due on Nov 30, 2017).

tecnocat commented 6 years ago

In our case is easier to put the fixed list of nodes in our app instead of wasting time to compiling for PHP 7.1.12.

Or use the compiled version from @garrows! Thanks!

qmcree commented 6 years ago

+1 for official Elasticache extension builds compatible with PHP 7.1 and 7.2. 😊

airinaga commented 6 years ago

@garrows I am trying your compiled version of the cluster client. But still getting the error below. I'm on php 7.1.14

Any ideas??

PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/amazon-elasticache-cluster-client.so' - libsasl2.so.2: cannot open shared object file: No such file or directory in Unknown on line 0

Any help is much appreciated!!!

sodabrew commented 6 years ago

@airinaga So you need libsasl2.so to be installed.

qmcree commented 6 years ago

https://packages.debian.org/search?keywords=libsasl2 https://secure.php.net/manual/en/memcached.installation.php (see bottom)

airinaga commented 6 years ago

@sodabrew Sorry for being lame, but how would this get installed on a RHEL box? I see above people used apt-get to install.. Doesn't look like yum has the same package. Or does this need to be built from source?

Thanks, Adam

sodabrew commented 6 years ago

Yum has the same package. I don't have a RHEL account to confirm the same version (i.e. libsasl2.so.2) but Fedora has this package: https://apps.fedoraproject.org/packages/cyrus-sasl-lib/

airinaga commented 6 years ago

So here are the symlinks I have in /usr/lib64/ ...

libsasl2.so -> libsasl2.so.3.0.0 libsasl2.so.2 -> libsasl2.so.3.0.0 libsasl2.so.3 -> libsasl2.so.3.0.0

I feel like I have the correct packages linked, attempting the symlink from solutions above would only create a symlink to a symlink. Ex: (ln libsasl2.so.2 libsasl2.so)

Still getting a 'cannot create session ID'

Any ideas?

Thanks, Adam

tobsn commented 6 years ago

Well... I used to do 7.0 on Elastic Beanstalk via:

03-phpcacheclient:
    command: curl -o clusterclient-aws-php7.tar.gz https://s3.amazonaws.com/elasticache-downloads/ClusterClient/PHP-7.0/latest-64bit && tar -xzf clusterclient-aws-php7.tar.gz && cp -f artifact/amazon-elasticache-cluster-client.so "$(php -r 'echo ini_get("extension_dir");')"
    test: "php -r \"exit((extension_loaded('memcached') ? 1 : 0));\""
    cwd: /tmp

That's now totally busted. Anyone know how to get this going with 7.1? Thanks a TON! :)

theoc31 commented 6 years ago

@QuChen88 @danzamansky @hyandell - When will this be updated to support PHP 7.2? At the moment we have some support via community for PHP 7.1 but what about PHP 7.2 that was released back in December 2017?

mclueppers commented 6 years ago

I've tried compiling it for PHP 7.2 on Alpine 3.7. It's finishing without any errors but fails to load the library with an error about a missing symbol

PHP Warning:  PHP Startup: Unable to load dynamic library 'memcached' (tried: /usr/lib/php/7.2/modules/memcached (Error loading shared library /usr/lib/php/7.2/modules/memcached: No such file or directory), /usr/lib/php/7.2/modules/memcached.so (Error relocating /usr/lib/php/7.2/modules/memcached.so: php_session_create_id: symbol not found)) in Unknown on line 0

I'm compiling it against PHP 7.1 now. Will give feedback if it fails again.

UPDATE: And it fails with same error for PHP 7.1. Testing with PHP 7.0 now

UPDATE 2: After changing the order of extensions to load php_session before memcached it's now working at least for PHP 7.2.

QuChen88 commented 6 years ago

Sounds like insane amount of activities are going on in PHP 7.x land. I will see what work is to create a PHP 7.2 artifact.

markhughes commented 6 years ago

Hey @QuChen88 did you have much luck with this?

QuChen88 commented 6 years ago

Yes I managed to build the PHP 7.2 client artifact on ubuntu 16.04 with libmemcached v1.0.8. Didn't have much luck with 1.0.18 for some reason...

See https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/issues/19

khoado93 commented 5 years ago

Excuse me, but could anyone please help me with this error?

I have deployed a Bitnami wordpress app on Ubuntu 16.04. and a memcached instance. When I installed the PHP memcached client extension, it still progressed and some missing header error occured with. I followed the instruction in the official AWS website, link below:

https://aws.amazon.com/vi/elasticache/memcached/wordpress-with-memcached/

However, I cannot access the website after server reboot. I restart apache services and get the error about unmatching modules mentioned above.

I tried to remove .so file and delete the "echo" line in php.ini file, but I still cannot get my site back online. Though I can use sftp and ssh to it, I cannot access it via public IP.

I also restarted the Ec2 instance, double checked the newly assigned IP as well as Internet gate way, route table and so on, everything is fine.

My wordpress installation is fresh, no plugin or modifying. I tried with another instance and it's gone the same way.

Now I just want to undo the memcached extension installation and my site return as before.

I am very thankful for your help. Thank you!

vincent-fletcher commented 4 years ago

Here is a PHP 7.1 compiled version built against libmemcached 1.0.18 (so seems to contain the memory fixes etc). https://drive.google.com/open?id=1Qxx4Xm2m3w7-ZjvnDvnygJ99FuPb0C7G