Skip to content

[php] Phalcon5 and PHP8.1 #7615

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

Merged
merged 6 commits into from
Oct 3, 2022
Merged
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
25 changes: 25 additions & 0 deletions frameworks/PHP/phalcon/app/config/config-mongo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Phalcon\Config;

return new Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'tfb-database',
'username' => 'benchmarkdbuser',
'password' => 'benchmarkdbpass',
'name' => 'hello_world',
'persistent' => true,
],
'mongodb' => [
'url' => 'mongodb://tfb-database:27017',
'db' => 'hello_world'
],
'application' => [
'controllersDir' => APP_PATH . '/app/controllers/',
'modelsDir' => APP_PATH . '/app/models/',
'collectionsDir' => APP_PATH . '/app/collections/',
'viewsDir' => APP_PATH . '/app/views/',
'baseUri' => '/',
]
]);
2 changes: 1 addition & 1 deletion frameworks/PHP/phalcon/app/config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Phalcon\Config;
use Phalcon\Config\Config;

return new Config([
'database' => [
Expand Down
6 changes: 3 additions & 3 deletions frameworks/PHP/phalcon/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"database": "MySQL",
"framework": "phalcon",
"language": "PHP",
"flavor": "PHP7",
"flavor": "PHP8.1",
"orm": "raw",
"platform": "FPM/FastCGI",
"webserver": "nginx",
Expand All @@ -34,7 +34,7 @@
"database": "MongoDB",
"framework": "phalcon",
"language": "PHP",
"flavor": "PHP7",
"flavor": "PHP8.1",
"orm": "raw",
"platform": "FPM/FastCGI",
"webserver": "nginx",
Expand All @@ -56,7 +56,7 @@
"database": "MySQL",
"framework": "phalcon",
"language": "PHP",
"flavor": "PHP7",
"flavor": "PHP8.1",
"orm": "raw",
"platform": "FPM/FastCGI",
"webserver": "nginx",
Expand Down
4 changes: 2 additions & 2 deletions frameworks/PHP/phalcon/deploy/conf/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /run/php/php7.4-fpm.pid
pid = /run/php/php-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
Expand Down Expand Up @@ -161,7 +161,7 @@ group = www-data
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php7.4-fpm.sock
listen = /run/php/php-fpm.sock

; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
Expand Down
2 changes: 1 addition & 1 deletion frameworks/PHP/phalcon/deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ http {


upstream fastcgi_backend {
server unix:/var/run/php/php7.4-fpm.sock;
server unix:/var/run/php/php-fpm.sock;
keepalive 40;
}

Expand Down
13 changes: 7 additions & 6 deletions frameworks/PHP/phalcon/phalcon-micro.dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get update -yqq > /dev/null && \
apt-get install -yqq nginx git unzip \
php7.4-cli php7.4-fpm php7.4-mysql php7.4-mbstring > /dev/null
php8.1-cli php8.1-fpm php8.1-mysql php8.1-mbstring php8.1-xml > /dev/null

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

COPY deploy/conf/* /etc/php/7.4/fpm/
COPY deploy/conf/* /etc/php/8.1/fpm/

ADD ./ /phalcon
WORKDIR /phalcon

RUN apt-get install -yqq php7.4-psr php7.4-phalcon > /dev/null
RUN apt-get install -y php-pear php8.1-dev > /dev/null
RUN pecl install phalcon-5.0.2 && echo "extension=phalcon.so" > /etc/php/8.1/fpm/conf.d/phalcon.ini

RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.4/fpm/php-fpm.conf ; fi;
RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.1/fpm/php-fpm.conf ; fi;

RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --ignore-platform-reqs

Expand All @@ -27,5 +28,5 @@ RUN chmod -R 777 app

EXPOSE 8080

CMD service php7.4-fpm start && \
CMD service php8.1-fpm start && \
nginx -c /phalcon/deploy/nginx.conf
2 changes: 2 additions & 0 deletions frameworks/PHP/phalcon/phalcon-mongodb.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ RUN apt-get install -yqq php7.4-psr php7.4-phalcon > /dev/null

RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet --ignore-platform-reqs

RUN mv /phalcon/public/index-mongo.php /phalcon/public/index.php

RUN chmod -R 777 app

EXPOSE 8080
Expand Down
13 changes: 7 additions & 6 deletions frameworks/PHP/phalcon/phalcon.dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get update -yqq > /dev/null && \
apt-get install -yqq nginx git unzip \
php7.4-cli php7.4-fpm php7.4-mysql php7.4-mbstring > /dev/null
php8.1-cli php8.1-fpm php8.1-mysql php8.1-mbstring php8.1-xml> /dev/null

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

COPY deploy/conf/* /etc/php/7.4/fpm/
COPY deploy/conf/* /etc/php/8.1/fpm/

ADD ./ /phalcon
WORKDIR /phalcon

RUN apt-get install -yqq php7.4-psr php7.4-phalcon > /dev/null
RUN apt-get install -y php-pear php8.1-dev > /dev/null
RUN pecl install phalcon-5.0.2 && echo "extension=phalcon.so" > /etc/php/8.1/fpm/conf.d/phalcon.ini

RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.4/fpm/php-fpm.conf ; fi;
RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.1/fpm/php-fpm.conf ; fi;

RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --ignore-platform-reqs

RUN chmod -R 777 app

EXPOSE 8080

CMD service php7.4-fpm start && \
CMD service php8.1-fpm start && \
nginx -c /phalcon/deploy/nginx.conf
5 changes: 2 additions & 3 deletions frameworks/PHP/phalcon/public/index-micro.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Phalcon\Mvc\Micro;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Exception as PhalconException;

try {
$app = new Micro();
Expand Down Expand Up @@ -101,6 +100,6 @@

$url = $_REQUEST['_url'] ?? '/';
$app->handle($url);
} catch (PhalconException $e) {
echo "PhalconException: ", $e->getMessage();
} catch (Exception $e) {
echo "Exception: ", $e->getMessage();
}
104 changes: 104 additions & 0 deletions frameworks/PHP/phalcon/public/index-mongo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

use MongoDB\Client;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\DI\FactoryDefault;
use Phalcon\Exception as PhalconException;
use Phalcon\Http\Request;
use Phalcon\Incubator\MongoDB\Mvc\Collection\Manager as MongoDBCollectionManager;
use Phalcon\Loader;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Model\MetaData\Apc;
use Phalcon\Mvc\Model\MetaData\Memory;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Volt;

define('APP_PATH', realpath('..'));
require APP_PATH . "/vendor/autoload.php";

try {
// Load the config
$config = include APP_PATH . "/app/config/config-mongo.php";

// Register an autoloader
$loader = new Loader();
$loader->registerDirs([
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->collectionsDir,
])->register();

// Create a DI
$di = new FactoryDefault();

// Setting up the router
$di->setShared('router', require APP_PATH . '/app/config/routes.php');

//MetaData
$di->setShared('modelsMetadata', function () {
if (function_exists('apc_store')) {
return new Apc();
}

return new Memory([
'metaDataDir' => APP_PATH . "/app/compiled-templates/"
]);
});

// Setting up the view component (seems to be required even when not used)
$di->setShared('view', function () use ($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines([
".volt" => function ($view) {
$volt = new Volt($view);
$volt->setOptions([
"path" => APP_PATH . "/app/compiled-templates/",
"extension" => ".compiled",
"separator" => '_',
]);

return $volt;
}
]);

return $view;
});

// Setting up the database connection
$di->setShared('db', function () use ($config) {
$database = $config->database;

return new Mysql([
'host' => $database->host,
'username' => $database->username,
'password' => $database->password,
'dbname' => $database->name,
'options' => [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_PERSISTENT => true,
],
]);
});

// Setting up the mongodb connection
$di->setShared('mongo', function () use ($config) {
$mongodbConfig = $config->mongodb;
$mongo = new Client($mongodbConfig->url);

return $mongo->selectDatabase($mongodbConfig->db);
});

// Registering the mongoDB CollectionManager service
$di->setShared('collectionsManager', function () {
return new MongoDBCollectionManager();
});

// Handle the request
$request = new Request();
$application = new Application();
$application->setDI($di);
$application->handle($request->getURI())->send();
} catch (PhalconException $e) {
echo "PhalconException: ", $e->getMessage();
}
9 changes: 4 additions & 5 deletions frameworks/PHP/phalcon/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
use MongoDB\Client;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\DI\FactoryDefault;
use Phalcon\Exception as PhalconException;
use Phalcon\Http\Request;
use Phalcon\Incubator\MongoDB\Mvc\Collection\Manager as MongoDBCollectionManager;
use Phalcon\Loader;
use Phalcon\Autoload\Loader;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Model\MetaData\Apc;
use Phalcon\Mvc\Model\MetaData\Memory;
Expand All @@ -22,7 +21,7 @@

// Register an autoloader
$loader = new Loader();
$loader->registerDirs([
$loader->setDirectories([
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->collectionsDir,
Expand Down Expand Up @@ -99,6 +98,6 @@
$application = new Application();
$application->setDI($di);
$application->handle($request->getURI())->send();
} catch (PhalconException $e) {
echo "PhalconException: ", $e->getMessage();
} catch (Exception $e) {
echo "Exception: ", $e->getMessage();
}