질문Q #15230
CI index.php parameters
학학이2016-09-20 13:22:11

CI 기존 소스 작업 중 질문있습니다.

CI를 웹 어플리케이션으로 사용하지 않고 shell script를 돌리는 용도로 사용중인 소스가 있습니다.

linux 서버 crontab 에 

*/1 * * * * /usr/bin/php /home/htdocs/shell/index.php getjob

1분 마다 도는 이런 cron이 등록되어있는데

 

index.php 뒤에 인자값을 주면 받아주는 내용이 index.php에서 없습니다. ( 제가 php를 잘 몰라서 못 찾는 걸수도 있습니다. )

index.php 는 그냥 웹 어플리케이션 CI index.php와 동일합니다.

 

어떤 과정을 통해 index.php가 파라미터를 받을 수 있는 건가요?

답변4
#1 배강민 2016-09-20 13:44:11

https://secure.php.net/manual/kr/reserved.variables.argv.php

게시판 이동합니다.

#2 학학이 2016-09-20 15:02:31
<?php

	define('ENVIRONMENT', 'development');

if (defined('ENVIRONMENT'))
{
	switch (ENVIRONMENT)
	{
		case 'development':
			error_reporting(E_ALL);
		break;
	
		case 'testing':
		case 'production':
			error_reporting(0);
		break;

		default:
			exit('The application environment is not set correctly.');
	}
}



	$system_path = 'system';


	$application_folder = 'application';


	// Set the current directory correctly for CLI requests
	if (defined('STDIN'))
	{
		chdir(dirname(__FILE__));
	}

	if (realpath($system_path) !== FALSE)
	{
		$system_path = realpath($system_path).'/';
	}

	// ensure there's a trailing slash
	$system_path = rtrim($system_path, '/').'/';

	// Is the system path correct?
	if ( ! is_dir($system_path))
	{
		exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
	}

/*
 * -------------------------------------------------------------------
 *  Now that we know the path, set the main path constants
 * -------------------------------------------------------------------
 */
	// The name of THIS file
	define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));

	// The PHP file extension
	// this global constant is deprecated.
	define('EXT', '.php');

	// Path to the system folder
	define('BASEPATH', str_replace("\\", "/", $system_path));

	// Path to the front controller (this file)
	define('FCPATH', str_replace(SELF, '', __FILE__));

	// Name of the "system folder"
	define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));


	// The path to the "application" folder
	if (is_dir($application_folder))
	{
		define('APPPATH', $application_folder.'/');
	}
	else
	{
		if ( ! is_dir(BASEPATH.$application_folder.'/'))
		{
			exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
		}

		define('APPPATH', BASEPATH.$application_folder.'/');
	}

/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *
 * And away we go...
 *
 */
require_once BASEPATH.'core/CodeIgniter.php';

index.php 는 다음과 같습니다. $argv 로 받는 부분이 없습니다.

 

#3 한대승(불의회상) 2016-09-20 15:05:27

CI로 만든거라면 아래 URL을 확인 하세요.

http://cikorea.net/user_guide_2.1.0/general/cli.html

#4 학학이 2016-09-20 15:10:41

@한대승

오 딱 찾던 내용입니다. 감사합니다.