
ElasticSearch vendors for PHPBenchmarking ElasticSearch vendors for PHP
Introduction
This article focuses on benchmarking open-source tools which help receive data from ElasticSearch into PHP.
We will check composer packages:
ruflin/elasticaelasticsearch/elasticsearch- plain PHP implementation with
curl.
Prerequisites
The infrastructure which we will use during this tutorial is pretty simple and based on using official Docker images:
- ElasticSearch — elasticsearch:5.3.0
- PHP-Cli — php:7.1-cli
- Composer — composer:php7
In this test, we have simple type inside ElasticSearch index which contains 1K records. Also, we will use all default setting for PHP and ElasticSearch.
Prepare infrastructure
With purpose perform this benchmark you need have installed Docker and curl on your machine. Run in terminal next commands:
Create folder for benchmark:
mkdir /tmp/php-es/Download code:
curl -o /tmp/php-es/index.php "https://gist.githubusercontent.com/cn007b/d8bd46eaf9eed1ceed2eb8eb4b15cc13/raw/3e0fed815d97fa0677516786a72aa932e6b87b43/index.php"curl -o /tmp/php-es/composer.json "https://gist.githubusercontent.com/cn007b/0f9ee7c466e94b962a15ae014330c177/raw/74454fdd0c8f3517b0ac87837f4797351077925a/composer.json"curl -o /tmp/php-es/import.sh "https://gist.githubusercontent.com/cn007b/af3b9f2db81c3b9c23de7257b2207f50/raw/7801c668134c22cb1b68c9a80c17e669dbebfef8/import.sh"
All code related to benchmarking available in file index.php you can check it out, or look it on github gist page.
Install composer packages:
docker run -ti --rm -v /tmp/php-es/:/app composer/composer:php7 installRun ElasticSearch:
docker run -d -p 9200:9200 --hostname localhost --name es elasticsearch:5.3.0IMPORTANT: please wait few seconds till request curl localhost:9200 return valid response.
Import data into ElasticSearch:
sh /tmp/php-es/import.shAs result you must receive message like this:
Imported:
{“count”:1000,”_shards”:{“total”:5,”successful”:5,”failed”:0}}Run benchmark
docker run -it --rm -v /tmp/php-es/:/app --link es php:7.1-cli php /app/index.phpThis command will perform benchmarking and will print result into console output.
Result
For me on ubuntu 16.04 with PHP 7.1.3 and ES 5.3.0 result was:
Elastica took: 0.115600
Elasticsearch took: 0.243299
Curl took: 0.006087
Bash took: 0.019164Conclusion
You can take into account this information with purpose to receive data from ElasticSearch into PHP as fast as possible. In this case, plain PHP with curl is the best option!
PS
All code available here: index.php, composer.json, import.sh.
You can find my success story of implementing fastest elasticsearch vendor on real project here.
