{"action":"created","issue":{"url":"https://api.github.com/repos/wp-cli/wp-cli/issues/1924","repository_url":"https://api.github.com/repos/wp-cli/wp-cli","labels_url":"https://api.github.com/repos/wp-cli/wp-cli/issues/1924/labels{/name}","comments_url":"https://api.github.com/repos/wp-cli/wp-cli/issues/1924/comments","events_url":"https://api.github.com/repos/wp-cli/wp-cli/issues/1924/events","html_url":"https://github.com/wp-cli/wp-cli/issues/1924","id":95408712,"number":1924,"title":"Running WPCLI in php script","user":{"login":"Thirty8Digital","id":10513960,"avatar_url":"https://avatars.githubusercontent.com/u/10513960?v=3","gravatar_id":"","url":"https://api.github.com/users/Thirty8Digital","html_url":"https://github.com/Thirty8Digital","followers_url":"https://api.github.com/users/Thirty8Digital/followers","following_url":"https://api.github.com/users/Thirty8Digital/following{/other_user}","gists_url":"https://api.github.com/users/Thirty8Digital/gists{/gist_id}","starred_url":"https://api.github.com/users/Thirty8Digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thirty8Digital/subscriptions","organizations_url":"https://api.github.com/users/Thirty8Digital/orgs","repos_url":"https://api.github.com/users/Thirty8Digital/repos","events_url":"https://api.github.com/users/Thirty8Digital/events{/privacy}","received_events_url":"https://api.github.com/users/Thirty8Digital/received_events","type":"Organization","site_admin":false},"labels":[{"id":203241,"url":"https://api.github.com/repos/wp-cli/wp-cli/labels/question","name":"question","color":"bfe5bf","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2015-07-16T10:58:34Z","updated_at":"2016-12-21T00:44:58Z","closed_at":"2015-07-20T23:27:26Z","body":"Hi\n\nForgive me if this is a silly question (it may well be) - but I've had success running WPCLI from the [cough] CLI. But now I'd like to call it from a PHP script. Is this possible / stupid / misguided? I have tried some shell_exec attempts but to no avail...\n\nThanks \n\nMike\n"},"comment":{"url":"https://api.github.com/repos/wp-cli/wp-cli/issues/comments/268402112","html_url":"https://github.com/wp-cli/wp-cli/issues/1924#issuecomment-268402112","issue_url":"https://api.github.com/repos/wp-cli/wp-cli/issues/1924","id":268402112,"user":{"login":"sun","id":41992,"avatar_url":"https://avatars.githubusercontent.com/u/41992?v=3","gravatar_id":"","url":"https://api.github.com/users/sun","html_url":"https://github.com/sun","followers_url":"https://api.github.com/users/sun/followers","following_url":"https://api.github.com/users/sun/following{/other_user}","gists_url":"https://api.github.com/users/sun/gists{/gist_id}","starred_url":"https://api.github.com/users/sun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sun/subscriptions","organizations_url":"https://api.github.com/users/sun/orgs","repos_url":"https://api.github.com/users/sun/repos","events_url":"https://api.github.com/users/sun/events{/privacy}","received_events_url":"https://api.github.com/users/sun/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T00:44:58Z","updated_at":"2016-12-21T00:44:58Z","body":"FWIW, I don't think that this should be \"officially supported\" by WP-CLI, but people may already be happy to come here and find a working solution.\r\n\r\nI've summarized the different suggestions into a quick script.  To use:\r\n\r\n1. Download/upload `wp-cli.phar` to your web space.\r\n\r\n1. Create `cli.php` (the script below) and upload it into the same folder of `wp-cli.phar`.\r\n\r\n1. Test that it works by accessing it; e.g., http://example.com/cli.php\r\n\r\n1. Replace the last arguments (`cli info`) within the script with your desired arguments and options in the same way you'd specify them normally on the command line.\r\n\r\n1. Access it again; e.g., by reloading.\r\n\r\n    Note that some commands (such as `search-replace`) assume `STDOUT` to be a writable stream resource, which doesn't exist in this execution context, so you will see errors like the following instead of the actual output:\r\n\r\n    > Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///path/to/htdocs/wp-cli.phar/vendor/wp-cli/php-cli-tools/lib/cli/Streams.php on line 66\r\n\r\n    I'm relatively sure there's a trick around that, but I didn't need that for my purposes.\r\n\r\n1. Delete both files `cli.php` and `wp-cli.phar`.\r\n\r\n---\r\n`cli.php`:\r\n```php\r\n<?php\r\n\r\nini_set('display_errors', 'on');\r\n//error_reporting(E_ALL);\r\necho \"<pre>\\n\";\r\n\r\n# @see https://github.com/wp-cli/wp-cli/issues/1924#issuecomment-122075194\r\n$GLOBALS['argv'] = explode(' ', 'wp --path=' . __DIR__ . ' cli info');\r\n\r\n# @see https://github.com/wp-cli/wp-cli/blob/master/php/boot-phar.php\r\nconst WP_CLI_ROOT = 'phar://wp-cli.phar';\r\ninclude WP_CLI_ROOT . '/php/wp-cli.php';\r\n\r\n?>\r\n```\r\n"}}
{"actor":{"display_login":"sun"}}