save function
This commit is contained in:
parent
2b329979c2
commit
0a8a8ecd72
@ -142,17 +142,18 @@ class JsonDb extends \Prowebcraft\Dot
|
|||||||
*/
|
*/
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
$lenght = strlen(json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX));
|
$v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX);
|
||||||
$try = 0;
|
$l = strlen($v);
|
||||||
while ($try < 5) {
|
$t = 0;
|
||||||
$written = file_put_contents($this->db, json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX)); // Multi user get a locker
|
while ($t < 5) {
|
||||||
if ($written == $lenght) {
|
$w = file_put_contents($this->db, $v); // Multi user get a locker
|
||||||
|
if ($w == $l) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$try++;
|
$try++;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
if ($written !== $lenght) {
|
if ($w !== $l) {
|
||||||
exit('Erreur d\'écriture, les données n\'ont pas été sauvegardées');
|
exit('Erreur d\'écriture, les données n\'ont pas été sauvegardées');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user