- Code: Select all
function __construct(){
//parent::__construct();
global $devid;
$this->lockFile = BASE_PATH.STATE_DIR.$devid.'.lock';
$this->lockId=uniqid(time());
}
function Locked (){
$locked = file_exists($this->lockFile) && filemtime($this->lockFile)>time()-30 && file_get_contents($this->lockFile)!=$this->lockId;
if(!$locked)
debugLog('Device is NOT locked');
else
debugLog('Device is locked');
return $locked;
}
function Unlock(){
if(file_exists($this->lockFile)){
debugLog('Unlocked device '.$GLOBALS['devid']);
unlink($this->lockFile);
}
}
function Lock(){
debugLog('Locked device '.$GLOBALS['devid']);
file_put_contents($this->lockFile, $this->lockId);
}
In the AlterPingChanges function I call $this->Lock();
In the GetMessageList function I call $this->Unlock();
And now the sad part is that I had to change the core code of z-push in request.php in the HandlePing function I added on line 976:
- Code: Select all
//check if another Ping process is already running
if($backend->Locked()){
$pingstatus=4;
break;
}
right after:
- Code: Select all
for($n=0;$n<$lifetime / $timeout; $n++ ) {
//check the remote wipe status
if (PROVISIONING === true) {
$rwstatus = $backend->getDeviceRWStatus($user, $auth_pw, $devid);
if ($rwstatus == SYNC_PROVISION_RWSTATUS_PENDING || $rwstatus == SYNC_PROVISION_RWSTATUS_WIPED) {
//return 7 because it forces folder sync
$pingstatus = 7;
break;
}
}
I hope this helps solving the issue!
