Skip to content

Commit 1bbf924

Browse files
committed
Fixed typo [skip ci]
1 parent 2e1c37b commit 1bbf924

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/docker/php/mysql-lock.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/usr/bin/env php
22
<?php
33
/**
4-
* Запуск команды с сетевой синхронизацией через MySQL.
4+
* Runs a command with network sync using MySQL.
55
*
6-
* Когда запускается сеть из docker-контейнеров каждый php-контейнер в числе
7-
* прочих запускает команду миграции БД. И, чтобы исключить высокую вероятность,
8-
* запуска нескольких таких процессов одновременно, используется синхронизация
9-
* на уровне блокировок MySQL. Это гарантирует, что одновременно будет работать
10-
* только одна из запущенных команд, а остальные будут ждать завершения.
6+
* When network of docker containers is starting, each php container executes
7+
* DB migration command. To except chance to execute many commands at the same time,
8+
* network sync is used. It uses `GET_LOCK()` and `RELEASE_LOCK()` MySQL functions.
9+
* This ensures monopoly execution. One of the commands will be run, and others will wait.
1110
*
1211
* @author Roman Zhuravlev <zhuravljov@gmail.com>
1312
*/
1413

1514
$params = $_SERVER['argv'];
1615
array_shift($params);
1716
$command = implode(' ', $params);
17+
$lockName = md5($command);
1818

1919
$mysql = new PDO(
2020
sprintf(
@@ -29,19 +29,21 @@
2929

3030
// Waiting a lock for the command
3131
$query = $mysql->prepare('SELECT GET_LOCK(?, -1)');
32-
$query->execute([md5($command)]);
32+
$query->execute([$lockName]);
3333
if (!$query->fetch(PDO::FETCH_NUM)[0]) {
34-
throw new Exception('Cannot get the lock.');
34+
echo basename(__FILE__) . ': cannot get the lock.' . PHP_EOL;
35+
exit(1);
3536
}
3637

3738
// Executes the command
3839
passthru($command, $exitCode);
3940

4041
// Releases the lock
4142
$query = $mysql->prepare('SELECT RELEASE_LOCK(?)');
42-
$query->execute([md5($command)]);
43+
$query->execute([$lockName]);
4344
if (!$query->fetch(PDO::FETCH_NUM)[0]) {
44-
throw new Exception('Cannot release the lock.');
45+
echo basename(__FILE__) . ': release the lock.' . PHP_EOL;
46+
exit(1);
4547
}
4648

4749
exit($exitCode);

0 commit comments

Comments
 (0)