

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 編譯適用於 PHP 的 ElastiCache 叢集用戶端原始碼
<a name="Appendix.PHPAutoDiscoveryCompile"></a>

本節說明如何取得及編譯適用於 PHP 的 ElastiCache 叢集用戶端之原始碼。

您需要從 GitHub 提取兩個套件並進行編譯：[aws-elasticache-cluster-client-libmemcached](https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached) 及 [aws-elasticache-cluster-client-memcached-for-php](https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php)。

**Topics**
+ [編譯 libmemcached 程式庫](#Appendix.PHPAutoDiscoveryCompile.Libmemcached)
+ [編譯適用於 PHP 的 ElastiCache Memcached 自動探索用戶端](#Appendix.PHPAutoDiscoveryCompile.Client)

## 編譯 libmemcached 程式庫
<a name="Appendix.PHPAutoDiscoveryCompile.Libmemcached"></a>

**編譯 aws-elasticache-cluster-client-libmemcached 程式庫**

1. 啟動 Amazon EC2 執行個體。

1. 安裝程式庫的依存項目。
   + Amazon Linux 201509 AMI

     ```
     sudo yum install gcc gcc-c++ autoconf libevent-devel
     ```
   + Ubuntu 14.04 AMI

     ```
     sudo apt-get update
     sudo apt-get install libevent-dev gcc g++ make autoconf libsasl2-dev
     ```

1. 提取儲存庫並編譯程式碼。

   ```
   Download and install [ https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/archive/v1.0.18.tar.gz]( https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/archive/v1.0.18.tar.gz)
   ```

## 編譯適用於 PHP 的 ElastiCache Memcached 自動探索用戶端
<a name="Appendix.PHPAutoDiscoveryCompile.Client"></a>

以下各節說明如何編譯 ElastiCache Memcached 自動探索用戶端

**Topics**
+ [編譯適用於 PHP 7 的 ElastiCache Memcached 用戶端](#Appendix.PHPAudiscoveryCompile.Client.PHP7)
+ [編譯適用於 PHP 5 的 ElastiCache Memcached 用戶端](#Appendix.PHPAudiscoveryCompile.PHP5)

### 編譯適用於 PHP 7 的 ElastiCache Memcached 用戶端
<a name="Appendix.PHPAudiscoveryCompile.Client.PHP7"></a>

在程式碼目錄下執行以下命令組。

```
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
sudo yum install php70-devel
phpize
./configure --with-libmemcached-dir=<libmemcached-install-directory> --disable-memcached-sasl
make
make install
```

**注意**  
您可以將 libmemcached 程式庫靜態連結至 PHP 二進位檔，讓它可以在各種 Linux 平台間移植。若要執行此作業，請在 `make` 前執行以下命令：  

```
sed -i "s#-lmemcached#<libmemcached-install-directory>/lib/libmemcached.a -lcrypt -lpthread -lm -lstdc++ -lsasl2#" Makefile 
```

### 編譯適用於 PHP 5 的 ElastiCache Memcached 用戶端
<a name="Appendix.PHPAudiscoveryCompile.PHP5"></a>

透過在 `aws-elasticache-cluster-client-memcached-for-php/` 資料夾下執行以下命令，來編譯 `aws-elasticache-cluster-client-memcached-for-php`。

```
git clone https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php.git
cd aws-elasticache-cluster-client-memcached-for-php 
sudo yum install zlib-devel
phpize
./configure --with-libmemcached-dir=<libmemcached-install-directory>
make
make install
```