-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[php] Slim to v4, php8.1 and adapterman (#7660)
* [php] Slim to v4 * Update to v4 * Add with adapterman
- Loading branch information
Showing
11 changed files
with
467 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
{ | ||
"require": { | ||
"slim/slim": "3.12.4", | ||
"slim/php-view": "3.2.0" | ||
"slim/slim": "^4.10", | ||
"slim/php-view": "3.2.0", | ||
"slim/psr7": "1.*", | ||
"slim/http": "1.*", | ||
"php-di/php-di": "^6.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Db\\": "db/" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
namespace db; | ||
|
||
use PDO; | ||
use PDOStatement; | ||
|
||
class Raw | ||
{ | ||
private static PDO $instance; | ||
public static PDOStatement $db; | ||
public static PDOStatement $fortune; | ||
public static PDOStatement $random; | ||
/** | ||
* @var []PDOStatement | ||
*/ | ||
private static $update; | ||
|
||
public static function init() | ||
{ | ||
$pdo = new PDO( | ||
'pgsql:host=tfb-database;dbname=hello_world', | ||
'benchmarkdbuser', | ||
'benchmarkdbpass', | ||
[ | ||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||
PDO::ATTR_EMULATE_PREPARES => false | ||
] | ||
); | ||
|
||
self::$fortune = $pdo->prepare('SELECT id,message FROM Fortune'); | ||
self::$random = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id = ?'); | ||
self::$instance = $pdo; | ||
} | ||
|
||
/** | ||
* Postgres bulk update | ||
* | ||
* @param array $worlds | ||
* @return void | ||
*/ | ||
public static function update(array $worlds) | ||
{ | ||
$rows = count($worlds); | ||
|
||
if (!isset(self::$update[$rows])) { | ||
$sql = 'UPDATE world SET randomNumber = CASE id' | ||
. str_repeat(' WHEN ?::INTEGER THEN ?::INTEGER ', $rows) | ||
. 'END WHERE id IN (' | ||
. str_repeat('?::INTEGER,', $rows - 1) . '?::INTEGER)'; | ||
|
||
self::$update[$rows] = self::$instance->prepare($sql); | ||
} | ||
|
||
$val = []; | ||
$keys = []; | ||
foreach ($worlds as $world) { | ||
$val[] = $keys[] = $world['id']; | ||
$val[] = $world['randomNumber']; | ||
} | ||
|
||
self::$update[$rows]->execute([...$val, ...$keys]); | ||
} | ||
|
||
/** | ||
* Alternative bulk update in Postgres | ||
* | ||
* @param array $worlds | ||
* @return void | ||
*/ | ||
public static function update2(array $worlds) | ||
{ | ||
$rows = count($worlds); | ||
|
||
if (!isset(self::$update[$rows])) { | ||
$sql = 'UPDATE world SET randomNumber = temp.randomNumber FROM (VALUES ' | ||
. implode(', ', array_fill(0, $rows, '(?::INTEGER, ?::INTEGER)')) . | ||
' ORDER BY 1) AS temp(id, randomNumber) WHERE temp.id = world.id'; | ||
|
||
self::$update[$rows] = self::$instance->prepare($sql); | ||
} | ||
|
||
$val = []; | ||
foreach ($worlds as $world) { | ||
$val[] = $world['id']; | ||
$val[] = $world['randomNumber']; | ||
//$update->bindParam(++$i, $world['id'], PDO::PARAM_INT); | ||
} | ||
|
||
self::$update[$rows]->execute($val); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#zend_extension=opcache.so | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.validate_timestamps=0 | ||
opcache.save_comments=0 | ||
opcache.enable_file_override=1 | ||
opcache.huge_code_pages=1 | ||
|
||
mysqlnd.collect_statistics = Off | ||
|
||
memory_limit = 512M | ||
|
||
opcache.jit_buffer_size = 128M | ||
opcache.jit = tracing | ||
|
||
disable_functions=header,header_remove,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,session_regenerate_id,set_time_limit |
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
Oops, something went wrong.