How to avoid indefinite blocking when using a PHP script to update a database table with an open / pending transaction?

I found that if I modify table X through SQLplus and do not make changes, then if my web application (which works like a PHP script in Apache in ModPHP mode) tries to make a change to table X it will block indefinitely until I make my changes through SQLplus.

This behavior is correct, but I want it to be a clean / reliable / simple tool allowing me to disconnect my web application after N seconds and emit an HTTP 409 error instead of blocking endlessly.

My first thought was to use pcntl_alarm (N) with a signal handler to catch SIGALRM after N seconds. But I found that pcntl_ * functions are typically removed from the Apache ModPHP module at compile time, apparently to avoid spoiling the signals that the Apache root process itself uses to control its children. This might be harmful for PHP scripts running through ModPHP to process their own SIGARLMs, but this is not the battle that I want to choose with my Ops team right now, so I should reject this approach.

My second thought is to fork / start the child process every time my application needs to change table X and the parent process to poll the child (possibly via select () on the pipe) until the operation is completed (success) or N seconds (time out + failure).

The second approach will work, but it strikes me as ugly, complex and fragile.

Does anyone know a better way, given the limitations of PHP version 5.2.11 and Apache version 1.3.41 (on Linux 2.6.9)?

+3
source share
2 answers

, , PHP pcntl _ *() ModPHP + Apache. Linux , PHP - script, , script, .

, ( pcntl_fork()), " , ", , N , - proc_open(), PHP ( stream_set_blocking()) stream_select(), .

. -, , , , , , , ( , ). , , , , , . , , .

, " ", , - PHP, Oracle, - "" X , N ". , , , ( - , ).

0

, - . - PHP MySQLi-, MySQL, mysqli:: options .

mysqli:: options, - , , . , , .

MySQLi ( MySQL 5), MySQL, , , .

Edit

, , , , . -, , , .

set_time_limit() PHP script, , PHP Fatal Error. , , ... PHP Fatal Errors .

, set_error_handler(). set_time_limit() . , . .

, reset set_time_limit() , restore_error_handler(), .

, , , , ?

+2

Source: https://habr.com/ru/post/1725096/


All Articles