PHP - How to wait for disk to be written after commit is called?

时间:2018-07-26 10:13:50

标签: php pdo transactions commit disk

I'm using postgresql. I have to call a jar file that does some operations after db read, within a php script.

$connection is a PDO. I have noticed the following behavoiurs:

Scenario 1:

$connection->commit();

exec_shell(java -jar jarname) //it does not give expected behaviour

Scenario 2:

$connection->commit();

sleep(60);

exec_shell(java -jar jarname) //it does give expected behaviour

So, the question is: how to wait until commit writes all data to disk before going on with instructions?

fsync is on in postgres.conf synchronous_commit is on in postgres.conf

1 个答案:

答案 0 :(得分:0)

我没有使用PDO的经验,但是如果您可以检查提交的结果,则可以 尝试这样的事情:

$commit_status = $connection->commit();
if($commit_status === TRUE)
{
  exec_shell(java -jar jarname)
}

只要您没有提交状态的响应exec_shell都不会被调用