{"id":29150304,"url":"https://github.com/humanmade/backdrop","last_synced_at":"2025-06-30T23:10:10.748Z","repository":{"id":15470680,"uuid":"18204023","full_name":"humanmade/Backdrop","owner":"humanmade","description":"Backdrop is a simple library that does one thing: allows you to run one-off tasks in the background.","archived":false,"fork":false,"pushed_at":"2015-03-11T03:38:08.000Z","size":196,"stargazers_count":46,"open_issues_count":1,"forks_count":5,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-06-30T16:14:51.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humanmade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-28T07:13:04.000Z","updated_at":"2024-08-28T18:42:43.000Z","dependencies_parsed_at":"2022-08-24T20:20:50.421Z","dependency_job_id":null,"html_url":"https://github.com/humanmade/Backdrop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/humanmade/Backdrop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2FBackdrop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2FBackdrop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2FBackdrop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2FBackdrop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humanmade","download_url":"https://codeload.github.com/humanmade/Backdrop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2FBackdrop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262864258,"owners_count":23376461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-30T23:10:10.034Z","updated_at":"2025-06-30T23:10:10.697Z","avatar_url":"https://github.com/humanmade.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backdrop\nBackdrop is a simple library that does one thing: allows you to run one-off\ntasks in the background.\n\n## How to Use\n```php\nfunction my_awesome_function( $id ) {\n\t// Download initial data to my site. Might take a long time!\n\t$data = wp_remote_get( 'http://example.com/' . $id );\n\n\tif ( is_wp_error( $data ) ) {\n\t\treturn $data;\n\t}\n\n\tupdate_option( 'initial_data', $data );\n}\n\nadd_action( 'init', function () {\n\tif ( ! get_option( 'initial_data' ) ) {\n\t\t$task = new \\HM\\Backdrop\\Task( 'my_awesome_function', get_current_user_id() );\n\t\t$task-\u003eschedule();\n\t}\n} );\n```\n\n## API\n### `Task::__construct( $callback [, $...] )`\nCreating a new task sets up all of the internal data for your task. Pass in your\ncallback followed by your arguments to the function, and Backdrop will call it\nin a background process.\n\n#### Arguments\n* `$callback`: Callback method you want to use. Can be any callable type\n  (including object methods and static methods) **except for anonymous\n  functions**. Closures cannot be serialized, so they cannot be used for\n  Backdrop callbacks. This is an internal PHP limitation.\n* `$...`: Any other arguments you'd like to pass to your callback, as variable\n  arguments. e.g. `new Task( 'a', 'b', 'c', 'd' )` maps to `a( 'b', 'c', 'd' )`\n\n#### Return Value\nNone (constructor).\n\n### `Task::schedule()`\nSchedules your task to run. Typically runs after your page has been rendered, in\na separate process.\n\nBackdrop de-duplicates tasks based on the arguments passed in. For example, you\ncan do `new Task( 'myfunc', 1 )` on every request, and only one will be run.\nAfter this has been run, the next call will schedule again.\n\nTo avoid this, you should pass in unique identifiers as needed. Everything that\nmakes your task unique should be passed in and used by your function, as global\nstate may change.\n\n#### Arguments\nNone.\n\n#### Return Value\nEither `true`, or a `WP_Error` on failure. The error object will indicate the\ntype of error; typically this is a `hm_backdrop_scheduled` if the task is\nalready scheduled to run or is currently running.\n\n### `Task::is_scheduled()`\nChecks whether your task is scheduled to run.\n\n#### Arguments\nNone.\n\n#### Return Value\nBoolean indicating whether your task is scheduled to run, or is already running.\n\n#### `Task::cancel()`\nCancels a previously scheduled task.\n\nNote that if the task is already running, this will not cancel execution; it\nsimply removes it from the tasks scheduled to run.\n\n#### Arguments\nNone.\n\n#### Return Value\nEither `true`, or a `WP_Error` on failure. The error object will indicate the\ntype of error; typically this is a `hm_backdrop_not_scheduled` if the task\nhasn't been scheduled.\n\n## Compatibility\nBackdrop is compatible with PHP 5.2 and upwards.\n\n### PHP 5.2\nUse the `HM_Backdrop_Task` class (and `HM_Backdrop_Server`).\n\n**Important note:** If subclassing `HM_Backdrop_Server` with 5.2 compatibility,\nyou *must* reimplement the `spawn` method, as PHP 5.2 does not include late\nstatic bindings. This is automatically handled for 5.3+.\n\nHere's a minimal implementation that you can use:\n\n```\nclass MyBackdrop_Server extends HM_Backdrop_Server {\n\tpublic static function spawn() {\n\t\treturn self::spawn_run( __CLASS__ );\n\t}\n}\n```\n\n### PHP 5.3+\nUse the `HM\\Backdrop\\Task` class (and `HM\\Backdrop\\Server`). You can also import\nthe classes with the `use` keyword; for example, `use HM\\Backdrop\\Task` will\nallow you to create tasks with `new Task`.\n\n## License\nBackdrop is licensed under the GPL version 2.\n\nCopyright 2014 Human Made Limited\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanmade%2Fbackdrop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumanmade%2Fbackdrop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanmade%2Fbackdrop/lists"}