{"id":5209,"date":"2011-01-29T21:03:31","date_gmt":"2011-01-29T12:03:31","guid":{"rendered":"http:\/\/fukata.org\/?p=5209"},"modified":"2017-08-11T22:58:49","modified_gmt":"2017-08-11T22:58:49","slug":"codeigniter2-use-commandline","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/5209\/","title":{"rendered":"[CodeIgniter2.x]\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u4f7f\u7528\u3057\u3066\u307f\u305f"},"content":{"rendered":"
\u3064\u3044\u306b\u3001CodeIgniter 2.0\u304c\u30ea\u30ea\u30fc\u30b9<\/a>\u3055\u308c\u307e\u3057\u305f\u3002PHP4\u5bfe\u5fdc\u3092\u6368\u3066\u3001PHP5.1\u4ee5\u4e0a\u304c\u5fc5\u9808\u3089\u3057\u3044\u3067\u3059\u3002\u307e\u3060\u3001\u5c11\u3057\u3057\u304b\u5185\u90e8\u306e\u30bd\u30fc\u30b9\u3092\u898b\u3066\u3044\u306a\u3044\u306e\u3067\u4f55\u3068\u3082\u8a00\u3048\u307e\u305b\u3093\u304c\u3001\u4e3b\u8981\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u305d\u308c\u307b\u3069\u5927\u304d\u306a\u9055\u3044\u306f\u306a\u304f\u3001CodeIgniter 1.x\u306e\u6642\u306e\u611f\u899a\u306bPHP5\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30bf\u30a4\u30eb\u3092\u9069\u7528\u3059\u308c\u3070\u7c21\u5358\u306b\u52d5\u304b\u305b\u307e\u3059\u3002<\/p>\n \u305d\u308c\u3067\u3001\u4eca\u56de\u65b0\u305f\u306b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n <\/p>\n \u76ee\u6b21<\/p> \u307e\u305a\u306f\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u547c\u3073\u51fa\u3059\u305f\u3081\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n \u81f3\u3063\u3066\u666e\u901a\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u3059\u306d\u3002\u305f\u3060\u3001\u3053\u306e\u307e\u307e\u3060\u3068WEB\u304b\u3089\u3082\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4ee5\u5916\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u306b\u306f\u30a8\u30e9\u30fc\u306b\u3059\u308b\u3002\u306a\u3069\u306e\u5bfe\u5fdc\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u4e0a\u8a18\u3067\u4f5c\u6210\u3057\u305f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u547c\u3073\u51fa\u3059\u306b\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n index.php\u4ee5\u964d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u304cURI\u3068\u3057\u3066\u6271\u308f\u308c\u307e\u3059\u3002<\/p>\n \u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u89e3\u6790\u81ea\u4f53\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3084\u3063\u3066\u3044\u308b\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n \u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5b9f\u884c\u65b9\u6cd5\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n \u305f\u3060\u3001index.php\u4ee5\u964d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u30b9\u30e9\u30c3\u30b7\u30e5\u300c\/\u300d\u3067\u9023\u7d50\u3059\u308b\u306e\u3067\u3001query_string\u306a\u3069\u3092\u6709\u52b9\u5316\u3057\u305f\u5834\u5408\u306a\u3069\u3092\u8003\u616e\u3059\u308b\u3068\u524d\u8005\u306e\u5f62\u5f0f\u3067\u6e21\u3057\u305f\u65b9\u304c\u9593\u9055\u3044\u304c\u5c11\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u3068\u3001\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u73fe\u5728\u306f\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u5b9f\u884c\u3059\u308b\u5834\u5408\u306bquery_string\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n CodeIgniter 2\u3067\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30bb\u30fc\u30d5\u30e2\u30fc\u30c9\u3067\u306f\u306a\u3044\u5834\u5408\u306b\u3001PHP\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u6700\u5927\u5b9f\u884c\u6642\u9593\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u3053\u308c\u306f\u3001\u4e0a\u8a18\u3067\u4f5c\u6210\u3057\u305f\u30d0\u30c3\u30c1\u306b\u3082\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001Example_batch\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u7121\u9650\u30eb\u30fc\u30d7\u3092\u884c\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n \u3067\u3001\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\uff13\uff10\uff10\u79d2\u304c\u7d4c\u904e\u3057\u305f\u6642\u306b\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n \u3053\u308c\u3092\u9632\u3050\u306b\u306f\u3001set_time_limit<\/a>\u30e1\u30bd\u30c3\u30c9\u306b0\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001\u7121\u5236\u9650\u306b\u306a\u308b\u306e\u3067\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u5185\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n \u624b\u8efd\u306b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001model\u3084helper\u3092\u30d0\u30c3\u30c1\u7b49\u3067\u518d\u5229\u7528\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3057\u305f\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u3064\u3044\u306b\u3001CodeIgniter 2.0\u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u307e\u3057\u305f\u3002PHP4\u5bfe\u5fdc\u3092\u6368\u3066\u3001PHP5.1\u4ee5\u4e0a\u304c\u5fc5\u9808\u3089\u3057\u3044\u3067\u3059\u3002\u307e\u3060\u3001\u5c11\u3057\u3057\u304b\u5185\u90e8\u306e\u30bd\u30fc\u30b9\u3092\u898b\u3066\u3044\u306a\u3044\u306e\u3067\u4f55\u3068\u3082\u8a00\u3048\u307e\u305b\u3093\u304c\u3001\u4e3b\u8981\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u305d\u308c\u307b … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[153,850],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/5209"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=5209"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/5209\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=5209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=5209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=5209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u4f5c\u6210<\/span><\/h2>\n
\r\nclass Example_batch extends CI_Controller {\r\n\tpublic function __construct() {\r\n\t\tparent::__construct();\r\n\t}\r\n\t\r\n\tpublic function hoge($name) {\r\n\t\techo \"name={$name}\\n\";\r\n\t}\r\n}\r\n<\/pre>\n
\r\nclass Example_batch extends CI_Controller {\r\n\tpublic function __construct() {\r\n\t\tparent::__construct();\r\n \/\/ \u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4ee5\u5916\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u3001404\u30a8\u30e9\u30fc\r\n\t\tif (!$this->input->is_cli_request()) {\r\n\t\t\tshow_404();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic function hoge($name) {\r\n\t\techo \"name={$name}\\n\";\r\n\t}\r\n}\r\n<\/pre>\n
\u5b9f\u884c<\/span><\/h2>\n
\r\n$ php [CI\u30c7\u30a3\u30ec\u30af\u30c8\u30ea]\/index.php \/example_batch\/hoge\/foo\/\r\nname=foo\r\n<\/pre>\n
system\/core\/URI.php#_parse_cli_args<\/span><\/h3>\n
\r\nprivate function _parse_cli_args()\r\n{\r\n\t$args = array_slice($_SERVER['argv'], 1);\r\n\r\n\treturn $args ? '\/' . implode('\/', $args) : '';\r\n}\r\n<\/pre>\n
\r\n$ php [CI\u30c7\u30a3\u30ec\u30af\u30c8\u30ea]\/index.php example_batch hoge foo\r\nname=foo\r\n<\/pre>\n
\u6700\u5927\u5b9f\u884c\u6642\u9593<\/span><\/h2>\n
system\/core\/CodeIgniter.php<\/span><\/h3>\n
\r\n\/*\r\n * ------------------------------------------------------\r\n * Set a liberal script execution time limit\r\n * ------------------------------------------------------\r\n *\/\r\n\tif (function_exists(\"set_time_limit\") == TRUE AND @ini_get(\"safe_mode\") == 0)\r\n\t{\r\n\t\t@set_time_limit(300);\r\n\t}\r\n<\/pre>\n
\r\npublic function while() {\r\n\twhile (true) {\r\n\t\techo \"\";\r\n\t}\r\n}\r\n<\/pre>\n
\r\n$ php index.php \/example_batch\/while\/\r\nPHP Fatal error: Maximum execution time of 300 seconds exceeded in [CI\u30c7\u30a3\u30ec\u30af\u30c8\u30ea]\/application\/controllers\/example_batch.php on line 20\r\n<\/pre>\n
\r\nclass Example_batch extends CI_Controller {\r\n\tpublic function __construct() {\r\n\t\tparent::__construct();\r\n \/\/ \u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4ee5\u5916\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u3001404\u30a8\u30e9\u30fc\r\n\t\tif (!$this->input->is_cli_request()) {\r\n\t\t\tshow_404();\r\n\t\t}\r\n\t\t\/\/ \u6700\u5927\u5b9f\u884c\u6642\u9593\u3092\u7121\u5236\u9650\u306b\u8a2d\u5b9a\r\n\t\tif (function_exists(\"set_time_limit\") == TRUE AND @ini_get(\"safe_mode\") == 0) {\r\n\t\t\t@set_time_limit(0);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic function hoge($name) {\r\n\t\techo \"name={$name}\\n\";\r\n\t}\r\n\r\n\tpublic function while() {\r\n\t\twhile (true) {\r\n\t\t\techo \"\";\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n