{"action":"created","issue":{"url":"https://api.github.com/repos/humanmade/backupwordpress/issues/1025","repository_url":"https://api.github.com/repos/humanmade/backupwordpress","labels_url":"https://api.github.com/repos/humanmade/backupwordpress/issues/1025/labels{/name}","comments_url":"https://api.github.com/repos/humanmade/backupwordpress/issues/1025/comments","events_url":"https://api.github.com/repos/humanmade/backupwordpress/issues/1025/events","html_url":"https://github.com/humanmade/backupwordpress/pull/1025","id":139714402,"number":1025,"title":"Utilise file locking so we can track crashed processes","user":{"login":"willmot","id":308507,"avatar_url":"https://avatars.githubusercontent.com/u/308507?v=3","gravatar_id":"","url":"https://api.github.com/users/willmot","html_url":"https://github.com/willmot","followers_url":"https://api.github.com/users/willmot/followers","following_url":"https://api.github.com/users/willmot/following{/other_user}","gists_url":"https://api.github.com/users/willmot/gists{/gist_id}","starred_url":"https://api.github.com/users/willmot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willmot/subscriptions","organizations_url":"https://api.github.com/users/willmot/orgs","repos_url":"https://api.github.com/users/willmot/repos","events_url":"https://api.github.com/users/willmot/events{/privacy}","received_events_url":"https://api.github.com/users/willmot/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/humanmade/backupwordpress/labels/Enhancement","name":"Enhancement","color":"d7e102"},{"url":"https://api.github.com/repos/humanmade/backupwordpress/labels/in%20progress","name":"in progress","color":"ededed"},{"url":"https://api.github.com/repos/humanmade/backupwordpress/labels/Needs%20Unit%20Tests","name":"Needs Unit Tests","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"willmot","id":308507,"avatar_url":"https://avatars.githubusercontent.com/u/308507?v=3","gravatar_id":"","url":"https://api.github.com/users/willmot","html_url":"https://github.com/willmot","followers_url":"https://api.github.com/users/willmot/followers","following_url":"https://api.github.com/users/willmot/following{/other_user}","gists_url":"https://api.github.com/users/willmot/gists{/gist_id}","starred_url":"https://api.github.com/users/willmot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willmot/subscriptions","organizations_url":"https://api.github.com/users/willmot/orgs","repos_url":"https://api.github.com/users/willmot/repos","events_url":"https://api.github.com/users/willmot/events{/privacy}","received_events_url":"https://api.github.com/users/willmot/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/humanmade/backupwordpress/milestones/3","html_url":"https://github.com/humanmade/backupwordpress/milestones/Future%20Release","labels_url":"https://api.github.com/repos/humanmade/backupwordpress/milestones/3/labels","id":52671,"number":3,"title":"Future Release","description":"Anything in the Future Release milestone is up for grabs.","creator":{"login":"willmot","id":308507,"avatar_url":"https://avatars.githubusercontent.com/u/308507?v=3","gravatar_id":"","url":"https://api.github.com/users/willmot","html_url":"https://github.com/willmot","followers_url":"https://api.github.com/users/willmot/followers","following_url":"https://api.github.com/users/willmot/following{/other_user}","gists_url":"https://api.github.com/users/willmot/gists{/gist_id}","starred_url":"https://api.github.com/users/willmot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willmot/subscriptions","organizations_url":"https://api.github.com/users/willmot/orgs","repos_url":"https://api.github.com/users/willmot/repos","events_url":"https://api.github.com/users/willmot/events{/privacy}","received_events_url":"https://api.github.com/users/willmot/received_events","type":"User","site_admin":false},"open_issues":63,"closed_issues":152,"state":"open","created_at":"2011-11-04T10:36:37Z","updated_at":"2016-03-13T13:56:11Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2016-03-09T22:04:03Z","updated_at":"2016-03-13T22:24:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/humanmade/backupwordpress/pulls/1025","html_url":"https://github.com/humanmade/backupwordpress/pull/1025","diff_url":"https://github.com/humanmade/backupwordpress/pull/1025.diff","patch_url":"https://github.com/humanmade/backupwordpress/pull/1025.patch"},"body":"We are currently [unable to tell whether the background PHP process that the backup is running in has crashed](https://github.com/humanmade/backupwordpress/issues/908) or is still running.  We create a `.backup_running` file to track that a backup is in progress, this file is then deleted when the backup completes. The problem is that if the backup process fatal errors, crashes or is killed for some reason that file is not deleted and thus the backup looks like it's still running.\r\n\r\nThis PR solves this issue with [file locking], which is supported in PHP with the [`flock`](http://php.net/manual/en/function.flock.php) function. Once set, a file lock ensures that the file cannot then be written to by another thread until the lock is removed by the first thread. The kicker for us, file locks are automatically cleaned up when a PHP process ends, no matter how it's ended. We can use that fact to detect crashed backups.\r\n\r\nIf the `.backup_running` file exists and is locked then the backup must still be running and crucially if the `.backup_running` file exists but the isn't locked then the backup process must have started and then ended before it could properly complete. Huzzah!\r\n\r\nWe're using [`symfony/LockHandler`](http://symfony.com/doc/current/components/filesystem/lock_handler.html) to make working with file locks easier."},"comment":{"url":"https://api.github.com/repos/humanmade/backupwordpress/issues/comments/196068721","html_url":"https://github.com/humanmade/backupwordpress/pull/1025#issuecomment-196068721","issue_url":"https://api.github.com/repos/humanmade/backupwordpress/issues/1025","id":196068721,"user":{"login":"willmot","id":308507,"avatar_url":"https://avatars.githubusercontent.com/u/308507?v=3","gravatar_id":"","url":"https://api.github.com/users/willmot","html_url":"https://github.com/willmot","followers_url":"https://api.github.com/users/willmot/followers","following_url":"https://api.github.com/users/willmot/following{/other_user}","gists_url":"https://api.github.com/users/willmot/gists{/gist_id}","starred_url":"https://api.github.com/users/willmot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willmot/subscriptions","organizations_url":"https://api.github.com/users/willmot/orgs","repos_url":"https://api.github.com/users/willmot/repos","events_url":"https://api.github.com/users/willmot/events{/privacy}","received_events_url":"https://api.github.com/users/willmot/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T22:24:32Z","updated_at":"2016-03-13T22:24:32Z","body":"https://github.com/humanmade/backupwordpress/commit/abb7e410a16bbf0fb25de477ec79896fedbf5b48 fixes https://github.com/humanmade/backupwordpress/issues/763"}}