Skip to content

PHP-239 - PHP 8 #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/.git
Dockerfile
Makefile
ext/configure.ac
.github
bin
vendor
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: build
on:
pull_request:
push:
branches:
- master
env:
BUILDKIT_PROGRESS: plain
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- run: make
111 changes: 5 additions & 106 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,9 @@
language: php
dist: trusty
sudo: true
addons:
apt:
packages:
- libssl-dev
- oracle-java8-installer
cache:
ccache: true
directories:
- ${HOME}/dependencies
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

dist: xenial
services:
- docker
env:
global:
# Configure the .phpt tests to be Travis friendly
- REPORT_EXIT_STATUS=1
- TEST_PHP_ARGS="-q -s output.txt -g XFAIL,FAIL,BORK,WARN,LEAK,SKIP -x --show-diff"
# Add the pip installation folder to the PATH, until https://github.com/travis-ci/travis-ci/issues/3563 is fixed
- PATH=${HOME}/.local/bin:${PATH}
# Indicate the cached dependencies directory
- CACHED_DEPENDENCIES_DIRECTORY=${HOME}/dependencies
# Add libuv source build for container based TravisCI
- LIBUV_VERSION=1.14.1
- LIBUV_ROOT_DIR=${CACHED_DEPENDENCIES_DIRECTORY}/libuv/${LIBUV_VERSION}
- PHP_DRIVER_BUILD_DIRECTORY=/tmp/php-driver/build
- CPP_DRIVER_SOURCE_DIRECTORY=${TRAVIS_BUILD_DIR}/lib/cpp-driver
- CPP_DRIVER_BUILD_DIRECTORY=${PHP_DRIVER_BUILD_DIRECTORY}/cpp-driver
- CPP_DRIVER_INSTALL_DIRECTORY=${CACHED_DEPENDENCIES_DIRECTORY}/cpp-driver

before_install:
# Configure, build, install (or used cached libuv)
- if [ ! -d "${LIBUV_ROOT_DIR}" ]; then
pushd /tmp;
wget -q http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz;
tar xzf libuv-v${LIBUV_VERSION}.tar.gz;
pushd /tmp/libuv-v${LIBUV_VERSION};
sh autogen.sh;
./configure --prefix=${LIBUV_ROOT_DIR};
make -j$(nproc) install;
popd;
popd;
else echo "Using Cached libuv v${LIBUV_VERSION}. Dependency does not need to be re-compiled";
fi
### Build and configure the PHP driver extension ###
- mkdir -p ${PHP_DRIVER_BUILD_DIRECTORY}
# Determine the version number for the C/C++ driver dependency
- export CPP_DRIVER_VERSION_MAJOR=$(grep CASS_VERSION_MAJOR ${CPP_DRIVER_SOURCE_DIRECTORY}/include/cassandra.h | sed 's/[^0-9]*//g')
- export CPP_DRIVER_VERSION_MINOR=$(grep CASS_VERSION_MINOR ${CPP_DRIVER_SOURCE_DIRECTORY}/include/cassandra.h | sed 's/[^0-9]*//g')
- export CPP_DRIVER_VERSION_PATCH=$(grep CASS_VERSION_PATCH ${CPP_DRIVER_SOURCE_DIRECTORY}/include/cassandra.h | sed 's/[^0-9]*//g')
- export CPP_DRIVER_VERSION=${CPP_DRIVER_VERSION_MAJOR}.${CPP_DRIVER_VERSION_MINOR}.${CPP_DRIVER_VERSION_PATCH}
- pushd lib/cpp-driver; export CPP_DRIVER_VERSION_SHA=$(git rev-parse --short HEAD); popd
# Build the C/C++ driver dependency (or used cached C/C++ driver)
- if [ ! -d "${CPP_DRIVER_INSTALL_DIRECTORY}/${CPP_DRIVER_VERSION}/${CPP_DRIVER_VERSION_SHA}" ]; then
mkdir -p ${CPP_DRIVER_BUILD_DIRECTORY};
pushd ${CPP_DRIVER_BUILD_DIRECTORY};
cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX:PATH=${CPP_DRIVER_INSTALL_DIRECTORY}/${CPP_DRIVER_VERSION}/${CPP_DRIVER_VERSION_SHA} -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCASS_USE_ZLIB=ON ${CPP_DRIVER_SOURCE_DIRECTORY};
make -j$(nproc) install;
pushd ${CPP_DRIVER_INSTALL_DIRECTORY}/${CPP_DRIVER_VERSION}/${CPP_DRIVER_VERSION_SHA}/lib;
rm -f libcassandra.{dylib,so};
mv libcassandra_static.a libcassandra.a;
popd;
popd;
else echo "Using Cached C/C++ driver v${CPP_DRIVER_VERSION}-${CPP_DRIVER_VERSION_SHA}. Dependency does not need to be re-compiled";
fi
# PHPize the extension for configuration and building
- pushd ${TRAVIS_BUILD_DIR}/ext && phpize && popd
# Configure, build, and install the extension
- pushd ${PHP_DRIVER_BUILD_DIRECTORY}
- LIBS="-lssl -lz -luv -lm -lstdc++" LDFLAGS="-L${CPP_DRIVER_INSTALL_DIRECTORY}/${CPP_DRIVER_VERSION}/${CPP_DRIVER_VERSION_SHA}/lib -L${LIBUV_ROOT_DIR}/lib" ${TRAVIS_BUILD_DIR}/ext/configure --with-cassandra=${CPP_DRIVER_INSTALL_DIRECTORY}/${CPP_DRIVER_VERSION}/${CPP_DRIVER_VERSION_SHA} --with-uv=${LIBUV_ROOT_DIR}
- make -j$(nproc) install
- popd
# Enable the extension
- echo "extension=cassandra.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
### Install CCM for Behat testing ###
- pip install --user ccm

before_script:
# Install composer dependencies
- composer self-update
- composer install -n
# Use the BEHAT_EXTRA_OPTIONS to supply options to Behat runs
- BEHAT_EXTRA_OPTIONS=
# Use the BEHAT_SKIP_TAGS to skip tests on TravisCI
- BEHAT_SKIP_TAGS=~@skip-ci
- export BEHAT_EXTRA_OPTIONS BEHAT_SKIP_TAGS
# Switch to Java 8 for non-java projects
- if [ $(uname -a | grep x86_64 >/dev/null) ]; then
ARCH_SUFFIX=amd64;
else ARCH_SUFFIX=i386;
fi
- if [ -d "/usr/lib/jvm/java-8-oracle-$ARCH_SUFFIX" ]; then
export JAVA_HOME="/usr/lib/jvm/java-8-oracle-$ARCH_SUFFIX";
else export JAVA_HOME="/usr/lib/jvm/java-8-oracle";
fi
- export PATH=${JAVA_HOME}/bin:${PATH}

- BUILDKIT_PROGRESS=plain
script:
# Execute .phpt tests
- pushd ${PHP_DRIVER_BUILD_DIRECTORY} && make test && popd
# Execute the unit tests
- ./bin/phpunit --testsuite unit
# Execute the Behat tests
- ./bin/behat --tags="${BEHAT_SKIP_TAGS}" ${BEHAT_EXTRA_OPTIONS}
- make
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM php:8.1
WORKDIR /tmp/cassandra-php-driver

RUN apt update -y \
&& apt install python3 pip cmake unzip mlocate build-essential git libuv1-dev libssl-dev libgmp-dev openssl zlib1g-dev libpcre3-dev openjdk-11-jre openjdk-11-jdk -y \
&& pip install git+https://github.com/riptano/ccm.git@master

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin
RUN docker-php-source extract \
&& install-php-extensions @composer intl zip pcntl gmp ast xdebug yaml

COPY lib lib
RUN cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCASS_BUILD_STATIC=OFF -DCASS_BUILD_SHARED=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_LIBDIR:PATH=lib -DCASS_USE_ZLIB=ON lib/cpp-driver \
&& make -j$(nproc) \
&& make install

RUN docker-php-source extract

COPY ext ext
ENV NO_INTERACTION true
RUN cd ext \
&& phpize \
&& LDFLAGS="-L/usr/local/lib" LIBS="-lssl -lz -luv -lm -lgmp -lstdc++" ./configure --with-cassandra=/usr/local \
&& make -j$(nproc) \
&& make test \
&& make install \
&& mv cassandra.ini /usr/local/etc/php/conf.d/docker-php-ext-cassandra.ini \
&& cd ..

RUN ext/doc/generate_doc.sh

COPY composer.json .
RUN composer install -n

COPY support support
COPY tests tests
COPY phpunit.xml .
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
RUN bin/phpunit --stop-on-error --stop-on-failure

COPY features features
COPY behat.yml .
RUN bin/behat --stop-on-failure --tags="~@skip-ci"

RUN make clean \
&& make clean -C ext

CMD ["bash"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all: build
build:
docker build . -t cassandra-php-driver
run:
docker run -v $$PWD/ext/doc:/tmp/cassandra-php-driver/ext/doc -it cassandra-php-driver
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This driver works exclusively with the Cassandra Query Language v3 (CQL3) and
Cassandra's native protocol. The current version works with:

* Apache Cassandra versions 2.1, 2.2 and 3.0+
* PHP 5.6, PHP 7.0, and PHP 7.1
* PHP 5.6, PHP 7.0, PHP 7.1 and PHP 8.1
* 32-bit (x86) and 64-bit (x64)
* Thread safe (TS) and non-thread safe (NTS)
* Compilers: GCC 4.1.2+, Clang 3.4+, and MSVC 2010/2012/2013/2015
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ environment:
PHP_BINARY_TOOLS_ARCHIVE: php-sdk-binary-tools-20110915.zip
PHP_BINARY_TOOLS_DIR: C:/projects
PHP_DOWNLOAD_URL_PREFIX: https://github.com/php/php-src/archive
PHP_SDK_DEPENDENCIES_DOWNLOAD_URL_PREFIX: http://windows.php.net/downloads/php-sdk
PHP_SDK_DEPENDENCIES_DOWNLOAD_URL_PREFIX: https://windows.php.net/downloads/php-sdk
PHP_SDK_LOCATION_PREFIX: C:/projects/dependencies/php-sdk
DEPENDENCIES_LOCATION_PREFIX: C:/projects/dependencies/libs
COMPOSER_CACHE_DIR: C:/projects/dependencies/composer
Expand Down Expand Up @@ -165,7 +165,7 @@ install:
# Determine if PHP libraries archive should be downloaded (cached)
If (!(Test-Path -Path "$($env:PHP_DEPENDENCIES_ARCHIVE)")) {
# Download the PHP dependencies archive
Start-FileDownload "$($env:PHP_SDK_DEPENDENCIES_DOWNLOAD_URL_PREFIX)/$($env:PHP_DEPENDENCIES_ARCHIVE)" -FileName $env:PHP_DEPENDENCIES_ARCHIVE
Start-FileDownload "$($env:PHP_SDK_DEPENDENCIES_DOWNLOAD_URL_PREFIX)/archives/$($env:PHP_DEPENDENCIES_ARCHIVE)" -FileName $env:PHP_DEPENDENCIES_ARCHIVE
}

# Determine if libuv should be installed (cached)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=8.1"
},
"require-dev": {
"behat/behat": "~3.0.6",
"phpunit/php-code-coverage": "~2.0",
"phpunit/php-token-stream": "~1.3",
"phpunit/phpunit": "~4.8",
"symfony/process": "~2.1"
"behat/behat": "^3.7",
"phpunit/php-code-coverage": "^7.0",
"phpunit/php-token-stream": "^3.1",
"phpunit/phpunit": "^8.5",
"symfony/process": "^5.4"
},
"config": {
"bin-dir": "bin/"
Expand Down
1 change: 0 additions & 1 deletion ext/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ libtool
ltmain.sh
missing
/autom4te.cache/
ex*.php
debug.ini
cassandra.log
4 changes: 2 additions & 2 deletions ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ __NOTE__: The build procedures only need to be performed for driver development

## Compatibility

* PHP 5.6, PHP 7.0, and PHP 7.1
* PHP 5.6, PHP 7.0, PHP 7.1 and PHP 8.1
* 32-bit (x86) and 64-bit (x64)
* Thread safe (TS) and non-thread safe (NTS)
* Compilers: GCC 4.1.2+, Clang 3.4+, and MSVC 2012/2015
Expand Down Expand Up @@ -90,7 +90,7 @@ add-apt-repository ppa:ondrej/php
apt-get update
```

Once completed PHP v5.6.x, v7.0.x, or v7.1.x can be installed:
Once completed PHP v5.6.x, v7.0.x, v7.1.x, or v8.1.x can be installed:

```bash
apt-get install build-essential cmake git libpcre3-dev php7.1-dev
Expand Down
2 changes: 1 addition & 1 deletion ext/doc/generate_doc.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
DIR=`dirname "$0"`
php -d extension=cassandra.so -d extension_dir="$DIR/../modules" "$DIR/generate_doc.php" $DIR/..
php "$DIR/generate_doc.php" $DIR/..
8 changes: 4 additions & 4 deletions ext/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ protocol and Cassandra Query Language v3.
<date>2019-01-16</date>
<time>21:05:52</time>
<version>
<release>1.3.3</release>
<api>1.3.3</api>
<release>1.4.0</release>
<api>1.4.0</api>
</version>
<stability>
<release>devel</release>
Expand Down Expand Up @@ -297,8 +297,8 @@ protocol and Cassandra Query Language v3.
<dependencies>
<required>
<php>
<min>7.2.0</min>
<max>7.99.99</max>
<min>8.0.0</min>
<max>8.99.99</max>
</php>
<pearinstaller>
<min>1.4.8</min>
Expand Down
37 changes: 35 additions & 2 deletions ext/php_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/* Resources */
#define PHP_DRIVER_CLUSTER_RES_NAME PHP_DRIVER_NAMESPACE " Cluster"
#define PHP_DRIVER_SESSION_RES_NAME PHP_DRIVER_NAMESPACE " Session"
#define PHP_DRIVER_PREPARED_STATEMENT_RES_NAME PHP_DRIVER_NAMESPACE " PreparedStatement"

static uv_once_t log_once = UV_ONCE_INIT;
static char *log_location = NULL;
Expand Down Expand Up @@ -134,6 +135,26 @@ php_driver_session_dtor(php5to7_zend_resource rsrc TSRMLS_DC)
}
}

static int le_php_driver_prepared_statement_res;
int
php_le_php_driver_prepared_statement()
{
return le_php_driver_prepared_statement_res;
}
static void
php_driver_prepared_statement_dtor(php5to7_zend_resource rsrc TSRMLS_DC)
{
php_driver_pprepared_statement *preparedStmt = (php_driver_pprepared_statement*) rsrc->ptr;

if (preparedStmt) {
cass_future_free(preparedStmt->future);
php_driver_del_peref(&preparedStmt->ref, 1);
pefree(preparedStmt, 1);
PHP_DRIVER_G(persistent_prepared_statements)--;
rsrc->ptr = NULL;
}
}

static void
php_driver_log(const CassLogMessage *message, void *data);

Expand Down Expand Up @@ -414,6 +435,7 @@ static PHP_GINIT_FUNCTION(php_driver)
php_driver_globals->uuid_gen_pid = 0;
php_driver_globals->persistent_clusters = 0;
php_driver_globals->persistent_sessions = 0;
php_driver_globals->persistent_prepared_statements = 0;
PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_varchar);
PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_text);
PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_blob);
Expand Down Expand Up @@ -454,6 +476,11 @@ PHP_MINIT_FUNCTION(php_driver)
PHP_DRIVER_SESSION_RES_NAME,
module_number);

le_php_driver_prepared_statement_res =
zend_register_list_destructors_ex(NULL, php_driver_prepared_statement_dtor,
PHP_DRIVER_PREPARED_STATEMENT_RES_NAME,
module_number);

php_driver_define_Exception(TSRMLS_C);
php_driver_define_InvalidArgumentException(TSRMLS_C);
php_driver_define_DomainException(TSRMLS_C);
Expand Down Expand Up @@ -598,19 +625,25 @@ PHP_MINFO_FUNCTION(php_driver)
{
char buf[256];
php_info_print_table_start();
php_info_print_table_header(2, PHP_DRIVER_NAMESPACE " support", "enabled");

php_info_print_table_row(2, PHP_DRIVER_NAMESPACE " support", "enabled");

snprintf(buf, sizeof(buf), "%d.%d.%d%s",
CASS_VERSION_MAJOR, CASS_VERSION_MINOR, CASS_VERSION_PATCH,
strlen(CASS_VERSION_SUFFIX) > 0 ? "-" CASS_VERSION_SUFFIX : "");
(strlen(CASS_VERSION_SUFFIX) > 0 ? "-" CASS_VERSION_SUFFIX : ""));
php_info_print_table_row(2, "C/C++ driver version", buf);

php_info_print_table_row(2, "PHP driver extension", "customized for persistent prepared statements");

snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_clusters));
php_info_print_table_row(2, "Persistent Clusters", buf);

snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_sessions));
php_info_print_table_row(2, "Persistent Sessions", buf);

snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_prepared_statements));
php_info_print_table_row(2, "Persistent Prepared Statements", buf);

php_info_print_table_end();

DISPLAY_INI_ENTRIES();
Expand Down
Loading