Created
June 5, 2024 17:50
-
-
Save DanielHe4rt/06a33261f0b58eb182c9c8edd4a6b42a to your computer and use it in GitHub Desktop.
ScyllaDB PHP Driver in a fresh Ubuntu 22.04 Docker Image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Tested in a 22.04 Ubuntu Docker VM | |
apt-get update -y \ | |
&& apt-get upgrade -y \ | |
&& apt-get install -y \ | |
autoconf \ | |
nano \ | |
pkg-config \ | |
sudo \ | |
wget \ | |
git \ | |
gcc \ | |
g++ \ | |
gdb \ | |
python3 \ | |
python3-pip \ | |
unzip \ | |
mlocate \ | |
build-essential \ | |
ninja-build \ | |
libasan8 \ | |
libssl-dev \ | |
libubsan1 \ | |
&& pip3 install cmake cqlsh \ | |
&& apt-get clean | |
# Installing LibUV | |
git clone --depth 1 -b v1.46.0 https://github.com/libuv/libuv.git \ | |
&& cd libuv \ | |
&& mkdir build \ | |
&& cd build \ | |
&& cmake -DBUILD_TESTING=OFF -DBUILD_BENCHMARKS=OFF -DLIBUV_BUILD_SHARED=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. \ | |
&& ninja install \ | |
&& cd ../.. \ | |
&& rm -rf libuv | |
# Installing ScyllaDB CPP Driver | |
git clone --depth 1 https://github.com/scylladb/cpp-driver.git scylladb-driver \ | |
&& cd scylladb-driver \ | |
&& mkdir build \ | |
&& cd build \ | |
&& cmake -DCASS_CPP_STANDARD=17 -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=ON -DCASS_USE_STD_ATOMIC=ON -DCASS_USE_TIMERFD=ON -DCASS_USE_LIBSSH2=ON -DCASS_USE_ZLIB=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC -Wno-error=redundant-move" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. \ | |
&& ninja install \ | |
&& cd ../.. \ | |
&& rm -rf scylladb-driver | |
# Installing Cassandra CPP Driver | |
git clone --depth 1 https://github.com/datastax/cpp-driver.git cassandra-driver \ | |
&& cd cassandra-driver \ | |
&& mkdir build \ | |
&& cd build \ | |
&& cmake -DCASS_CPP_STANDARD=17 -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=ON -DCASS_USE_STD_ATOMIC=ON -DCASS_USE_TIMERFD=ON -DCASS_USE_LIBSSH2=ON -DCASS_USE_ZLIB=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC -Wno-error=redundant-move" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. \ | |
&& ninja install \ | |
&& cd ../.. \ | |
&& rm -rf cassandra-driver | |
# Installing TZData | |
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime | |
DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata | |
dpkg-reconfigure --frontend noninteractive tzdata | |
# Cloning the Driver and Installing dependencies | |
git clone --recursive https://github.com/he4rt/scylladb-php-driver.git \ | |
&& apt install -y \ | |
python3 \ | |
python3-pip \ | |
unzip \ | |
mlocate \ | |
build-essential \ | |
ninja-build \ | |
libgmp-dev \ | |
zlib1g-dev \ | |
openssl \ | |
libpcre3-dev \ | |
php-dev \ | |
&& pip3 install cmake | |
# Building the Driver | |
cd scylladb-php-driver \ | |
&& cmake --preset Release \ | |
&& cd out/Release \ | |
&& sudo ninja install | |
## Copying the driver to the PHP extension directory | |
cp ../../cassandra.ini /etc/php/8.1/cli/conf.d/10-cassandra.ini | |
cp cassandra.so /usr/lib/php/20210902/cassandra.so | |
php --ini | grep "10-cassandra.ini" | |
if [ $? -eq 0 ]; then | |
echo "ScyllaDB PHP extension installed successfully" | |
cd / | |
rm -rf scylladb-php-driver | |
cd ~ | |
echo "Try to run any script that uses the ScyllaDB PHP extension and don't forget to add a valid node IP address" | |
else | |
echo "ScyllaDB PHP extension installation failed" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Cassandra\Cluster; | |
$builder = Cassandra::cluster() | |
->withContactPoints('scylla-node1') | |
->withPort(9042) | |
->withCredentials('cassandra', 'cassandra') | |
->withPersistentSessions(true) | |
->withTokenAwareRouting(true) | |
->withConnectTimeout(15.0) | |
->build(); | |
$session = $builder->connect(); | |
$statement = new Cassandra\SimpleStatement( // also supports prepared and batch statements | |
'SELECT key, build_id, build_mode, version from system.versions' | |
); | |
$result = $session->execute($statement); | |
foreach ($result as $row) { // results and rows implement Iterator, Countable and ArrayAccess | |
var_dump($row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gódi