Skip to content

Commit

Permalink
fix: mongodb handler, dockerfile
Browse files Browse the repository at this point in the history
- Fixed MongoDB handler with correct MongoDB classes. This is apparently pretty old handler. Added suggests to the composer.json
- In Dockerfile using wget instead of git to get the phpiredis repository; installed mongodb
  • Loading branch information
PAXANDDOS committed Mar 23, 2023
1 parent 0ac1b11 commit 4a23ffb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ RUN apk add --no-cache -t .production-deps \
hiredis libzip

RUN set -xe \
&& apk add --no-cache -t .build-deps $PHPIZE_DEPS git \
&& apk add --no-cache -t .build-deps $PHPIZE_DEPS \
hiredis-dev libzip-dev \
&& pecl install -f apcu-5.1.22 redis-5.3.7 \
&& git clone https://github.com/nrk/phpiredis.git \
&& pecl install -f apcu-5.1.22 redis-5.3.7 mongodb-1.15.1 \
&& wget -qO- https://github.com/nrk/phpiredis/archive/v1.1.zip | busybox unzip - \
&& ( \
cd phpiredis \
&& git checkout v1.1 \
cd phpiredis-1.1 \
&& phpize \
&& ./configure --enable-phpiredis \
&& make \
&& make install \
) \
&& rm -r phpiredis \
&& rm -r phpiredis-1.1 \
&& docker-php-source extract \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install -j$(nproc) pcntl zip \
&& docker-php-ext-enable apcu redis phpiredis \
&& docker-php-ext-enable apcu redis mongodb phpiredis \
&& docker-php-source delete \
&& pecl clear-cache \
&& rm -rf /tmp/* \
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
"symfony/console": "^5.4|^6.0"
},
"suggest": {
"ext-phpiredis": "Native PHP extension for Redis connectivity. Predis will automatically utilize when available.",
"symfony/process": "To run the speed test command.",
"symfony/yaml": "To use the YAML config file."
"ext-mongodb": "For using the MongoDB logger.",
"ext-phpiredis": "For using native Redis connectivity.",
"mongodb/mongodb": "For using the MongoDB logger.",
"symfony/process": "For using the speed test command.",
"symfony/yaml": "For using the YAML configuration file."
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"mongodb/mongodb": "^1.0",
"symfony/process": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0"
},
Expand Down
40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
version: "3.9"

services:
resque:
container_name: resque
image: resque:latest
restart: unless-stopped
stdin_open: true
tty: true
build:
context: .
args:
- PHP_VERSION=7
ports:
- 8000:80
volumes:
- ./:/var/www/resque:rw
resque:
container_name: resque
image: resque:latest
restart: unless-stopped
stdin_open: true
tty: true
build:
context: .
args:
- PHP_VERSION=7
ports:
- 8000:80
volumes:
- ./:/var/www/resque:rw

redis:
container_name: resque-redis
image: redis:7.0-alpine
volumes:
- redis:/data:rw
redis:
container_name: resque-redis
image: redis:7.0-alpine
volumes:
- redis:/data:rw

volumes:
redis:
redis:
7 changes: 3 additions & 4 deletions src/Logger/Handler/Connector/MongoDBConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Resque\Logger\Handler\Connector;

use MongoDB\Client;
use Monolog\Handler\MongoDBHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -30,10 +31,8 @@ public function resolve(Command $command, InputInterface $input, OutputInterface
$dsn = strtr('mongodb://host:port', $args);
$options = [];

if (class_exists('MongoClient')) {
$mongodb = new \MongoClient($dsn, $options);
} elseif (class_exists('Mongo')) {
$mongodb = new \Mongo($dsn, $options);
if (class_exists(Client::class)) {
$mongodb = new Client($dsn, $options);
}

return new MongoDBHandler($mongodb, $this->replacePlaceholders($args['dbname']), $this->replacePlaceholders($args['collection']));
Expand Down

0 comments on commit 4a23ffb

Please sign in to comment.