Skip to content

Commit bf005e5

Browse files
jcherondvaknheo
authored andcommitted
[Ubiquity] Update to PHP 8 (TechEmpower#6187)
* update php version to 8.0 * set default fetch mode * remove DbTrait * remove DbTrait usage
1 parent cd20fe0 commit bf005e5

File tree

10 files changed

+19
-37
lines changed

10 files changed

+19
-37
lines changed

frameworks/PHP/ubiquity/app/controllers/Cache.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Bench controller.
88
*/
99
class Cache extends \Ubiquity\controllers\Controller {
10-
use DbTrait;
1110

1211
protected $cache;
1312

@@ -23,7 +22,7 @@ public function index() {}
2322

2423
public function cachedquery($queries = 1) {
2524
$worlds = [];
26-
$count = $this->getCount($queries);
25+
$count = \min(\max((int) $queries, 1), 500);
2726
while ($count --) {
2827
$worlds[] = ($this->cache->fetch('models\\CachedWorld', \mt_rand(1, 10000)))->_rest;
2928
}

frameworks/PHP/ubiquity/app/controllers/Db.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
use Ubiquity\orm\SDAO;
55
use models\World;
6-
use controllers\utils\DbTrait;
76

87
/**
98
* Bench controller.
109
*/
1110
class Db extends \Ubiquity\controllers\Controller {
12-
use DbTrait;
1311

1412
public function __construct() {}
1513

@@ -26,7 +24,7 @@ public function index() {
2624

2725
public function query($queries = 1) {
2826
$worlds = [];
29-
$count = $this->getCount($queries);
27+
$count = \min(\max((int) $queries, 1), 500);
3028
for ($i = 0; $i < $count; ++ $i) {
3129
$worlds[] = (SDAO::getById(World::class, [
3230
'id' => \mt_rand(1, 10000)
@@ -38,7 +36,7 @@ public function query($queries = 1) {
3836
public function update($queries = 1) {
3937
$worlds = [];
4038

41-
$count = $this->getCount($queries);
39+
$count = \min(\max((int) $queries, 1), 500);
4240
$ids = $this->getUniqueRandomNumbers($count);
4341
foreach ($ids as $id) {
4442
$world = SDAO::getById(World::class, [

frameworks/PHP/ubiquity/app/controllers/DbMongo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function warmup() {
1616

1717
public function update($queries = 1) {
1818
$worlds = [];
19-
$count = $this->getCount($queries);
19+
$count = \min(\max((int) $queries, 1), 500);
2020
$ids = $this->getUniqueRandomNumbers($count);
2121
foreach ($ids as $id) {
2222
$world = self::$pDao->execute([

frameworks/PHP/ubiquity/app/controllers/DbMy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DbMy extends Db_ {
1010

1111
public function update($queries = 1) {
1212
$worlds = [];
13-
$count = $this->getCount($queries);
13+
$count = \min(\max((int) $queries, 1), 500);
1414
$ids = $this->getUniqueRandomNumbers($count);
1515
foreach ($ids as $id) {
1616
$world = self::$pDao->execute([

frameworks/PHP/ubiquity/app/controllers/DbRaw.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Bench controller.
88
*/
99
class DbRaw extends \Ubiquity\controllers\Controller {
10-
use DbTrait;
1110

1211
protected static $statement;
1312

@@ -44,7 +43,7 @@ public function index() {
4443

4544
public function query($queries = 1) {
4645
$worlds = [];
47-
$count = $this->getCount($queries);
46+
$count = \min(\max((int) $queries, 1), 500);
4847
while ($count --) {
4948
self::$statement->execute([
5049
\mt_rand(1, 10000)
@@ -57,7 +56,7 @@ public function query($queries = 1) {
5756
public function update($queries = 1) {
5857
$worlds = [];
5958
$keys = $values = [];
60-
$count = $this->getCount($queries);
59+
$count = \min(\max((int) $queries, 1), 500);
6160
for ($i = 0; $i < $count; ++ $i) {
6261
$values[] = $keys[] = $id = \mt_rand(1, 10000);
6362
self::$statement->execute([

frameworks/PHP/ubiquity/app/controllers/Db_.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Bench controller.
1010
*/
1111
class Db_ extends \Ubiquity\controllers\Controller {
12-
use DbTrait,DbAsyncTrait;
12+
use DbAsyncTrait;
1313

1414
public function index() {
1515
echo \json_encode(self::$pDao->execute([
@@ -19,7 +19,7 @@ public function index() {
1919

2020
public function query($queries = 1) {
2121
$worlds = [];
22-
$count = $this->getCount($queries);
22+
$count = \min(\max((int) $queries, 1), 500);
2323

2424
while ($count --) {
2525
$worlds[] = (self::$pDao->execute([
@@ -31,7 +31,7 @@ public function query($queries = 1) {
3131

3232
public function update($queries = 1) {
3333
$worlds = [];
34-
$count = $this->getCount($queries);
34+
$count = \min(\max((int) $queries, 1), 500);
3535

3636
while ($count --) {
3737
$world = self::$pDao->execute([

frameworks/PHP/ubiquity/app/controllers/utils/DbTrait.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

frameworks/PHP/ubiquity/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require" : {
3-
"php" : "^7.4",
3+
"php" : ">=7.4",
44
"phpmv/ubiquity" : "dev-master"
55
},
66
"require-dev" : {

frameworks/PHP/ubiquity/deploy/conf/ubiquity-config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"user" => "benchmarkdbuser", // benchmarkdbuser
1111
"password" => "benchmarkdbpass", // benchmarkdbpass
1212
"options" => [
13-
\PDO::ATTR_PERSISTENT => true
13+
\PDO::ATTR_PERSISTENT => true,
14+
\PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
1415
],
1516
"cache" => false
1617
]
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:20.10
22

33
ARG DEBIAN_FRONTEND=noninteractive
44

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

1010
RUN apt-get install -yqq composer > /dev/null
1111

12-
COPY deploy/conf/* /etc/php/7.4/fpm/
12+
COPY deploy/conf/* /etc/php/8.0/fpm/
1313

1414
ADD ./ /ubiquity
1515
WORKDIR /ubiquity
1616

17-
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;
17+
RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.0/fpm/php-fpm.conf ; fi;
1818

1919
RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
2020

2121
RUN chmod 777 -R /ubiquity/app/cache/*
2222

2323
COPY deploy/conf/ubiquity-config.php app/config/config.php
2424

25-
RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/fpm/php.ini
25+
RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/8.0/fpm/php.ini
2626

27-
CMD service php7.4-fpm start && \
27+
CMD service php8.0-fpm start && \
2828
nginx -c /ubiquity/deploy/nginx.conf -g "daemon off;"

0 commit comments

Comments
 (0)