$hoge_array = array("", "", "hoge");
$fuga_array = array_diff( $hoge_array, array( "" ) );
print_r($fuga_array );
参考)
phpで、array(配列)の空要素を取り除く - カサヒラボ http://d.hatena.ne.jp/kasahi/20070605/1181027762
$hoge_array = array("", "", "hoge");
$fuga_array = array_diff( $hoge_array, array( "" ) );
print_r($fuga_array );
・get_list 表示例
# php -f chk_memcached.php get_list
==============================
command:get_list
==============================
* = old cache
---------------
expire = 0 | size = 10 | cache_key = foo
expire = 0 | size = 20 | cache_key = hoge
---------------
key count:2
total cache size: 30byte
*old total cache size: 0byte
#define('MEM_HOST', 'localhost');
define('MEM_HOST', '127.0.0.1');
define('MEM_PORT', 11211);
if ($argc < 2) {
showUsage();
exit;
}
$output = array();
$keys = array();
$value = '';
//Memcache
$memcache_obj = new Memcache;
$memcache_obj->connect(MEM_HOST, MEM_PORT);
array_shift($argv);
$command = array_shift($argv);
switch ($command) {
case 'get':
$keys = $argv;
$re = $memcache_obj->get($keys);
break;
case 'get_list':
$re = getKeyList($memcache_obj);
break;
case 'set':
$keys = array_shift($argv);
$value = array_shift($argv);
$re = $memcache_obj->set($keys, $value);
break;
case 'delete':
$keys = array_shift($argv);
$re = $memcache_obj->delete($keys);
break;
default:
showUsage();
break;
}
$output[] = '==============================';
$output[] = 'command:' . $command;
if (is_array($keys)) $keys = join(',', $keys);
if ($keys) $output[] = 'key(s):' . $keys;
if ($value) $output[] = 'value:' . $value;
$output[] = '==============================';
$output[] = '';
echo join("\n", $output);
if (is_array($re)) var_dump($re);
else echo $re;
echo "\n";
function showUsage() {
$usage = basename(__FILE__) . " -- Usage >>>>\n";
$usage.= " :get_list\n";
$usage.= " :get [key1] [key2] [key3] ... [keyN]\n";
$usage.= " :set [key] [value]\n";
$usage.= " :delete [key]\n";
echo $usage;
}
/**
* 統計情報からすべてのキーを抜き出す
*/
function getKeyList($memcache_obj) {
$result = array();
$tmp_keys = array();
$all_keys = array();
$total = 0;
$old_total = 0;
$slabs = $memcache_obj->getExtendedStats('slabs');
$stats = $memcache_obj->getStats();
$memcached_started_time = $stats['time'] - $stats['uptime'];
$stats_item = $memcache_obj->getStats('items');
$items = $stats_item['items'];
foreach ($items as $slabclass => $item) {
$stats_cachedump = $memcache_obj->getStats('cachedump', $slabclass, $item['number']);
$tmp_keys = array_merge($tmp_keys, $stats_cachedump);
}
ksort($tmp_keys);
foreach ($tmp_keys as $cache_key => $v) {
$size = (int)$v[0];
$time = ($v[1] == $memcached_started_time)? 0: $v[1];
$expire = (!$time)? $time: date('Y/m/d H:i:s', $time);
$old_flg = ($time && $time < time())? '*': ' ';
$total+=$size;
if ($old_flg == '*') $old_total+=$size;
$all_keys[] = 'expire = ' . $expire . $old_flg . ' | size = ' . sprintf("%8s", $size) . ' | cache_key = ' . $cache_key;
}
$result[] = '* = old cache';
$result[] = '--------------- ';
$result[] = join("\n", $all_keys);
$result[] = '--------------- ';
$result[] = 'key count:' . count($all_keys);
$result[] = ' total cache size:' . sprintf("%10s", $total) . 'byte';
$result[] = '*old total cache size:' . sprintf("%10s", $old_total) . 'byte';
return join("\n", $result);
}
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
// 21 文字目から 14 文字ぶん読み込みます
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
file_get_contents("http://user:password@www.example.com/");
// ストリームを作成します
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Basic " .base64_encode("user:password"). "\r\n"
)
// 上で設定した HTTP ヘッダを使用してファイルをオープンします
$file = file_get_contents('http://www.example.com/', false, stream_context_create($opts));
// ストリームを作成します
$header = Array(
"Content-Type: application/x-www-form-urlencoded",
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
"Accept-language: en",
"Cookie: foo=bar"
);
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>join("\r\n", $header),
)
);
$context = stream_context_create($opts);
// 上で設定した HTTP ヘッダを使用してファイルをオープンします
$file = file_get_contents('http://www.example.com/', false, $context);
$data = array(
'param1' => 'hoge',
'param2' => 'hogehoge',
);
$opt = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data),
));
$contents = file_get_contents('http://www.example.com/', false, stream_context_create($opt));
$app>cake bake---------------------------------------------------------------App : appPath: /hoge/huga/app---------------------------------------------------------------Interactive Bake Shell---------------------------------------------------------------[D]atabase Configuration[M]odel[V]iew[C]ontroller[P]roject[F]ixture[T]est case[Q]uitWhat would you like to Bake? (D/M/V/C/P/F/T/Q)
HTTP/1.1 200 OKDate: Thu, 05 May 2011 07:19:18 GMTServer: ApacheX-Powered-By: PHP/5.3.5Vary: Accept-EncodingContent-Encoding: gzipContent-Length: 977Content-Type: text/htmlKeep-Alive: timeout=5, max=100Connection: Keep-Alive
HTTP/1.1 200 OKDate: Thu, 05 May 2011 07:28:49 GMTServer: ApacheX-Powered-By: PHP/5.3.5Vary: Accept-EncodingContent-Encoding: gzipContent-Length: 977Keep-Alive: timeout=5, max=100Connection: Keep-Alive
Auto-load Helperに設定$autoload['helper'] = array('url');※各コントローラで指定するなら、$this->load->helper('url');
class MY_Controller extends CI_Controller {private $vars = array();/*** Constructor*/public function __construct(){parent::__construct();}/*** set vars* @access public* @param $key string* @param $val string* @return*/public function setVars($key, $val){$this->vars[$key] = $val;}/*** set views* @access public* @param $view mixed* @param $return bool* @return void*/public function setView($view, $return = FALSE){// common header$this->load->view('parts/header', $this->vars);if (is_array($view)){foreach ($view as $k) $this->load->view($k, $this->vars);}else{$this->load->view($view, $this->vars);}// common footer$this->load->view('parts/footer', $this->vars);}}
…略<title>My Site Title - <?=$title?></title>…略
/*** list*/public function list(){$this->setVars('title', 'HOGE LIST');$this->setView('hoge/list');}/*** edit*/public function edit(){$this->setVars('title', 'HOGE EDIT');$this->setView('hoge/edit');}}
ビュー : CodeIgniter ユーザガイド 日本語版http://codeigniter.jp/user_guide_ja/general/views.html→複数のビューの読み込み
app/views/parts_hook┠ header.php┗ footer.php※それぞれ HTMLのヘッダー部分とフッター部分
/*** ControllerCallback Class*/class ControllerCallback {/*** beforeFilter - post_controller_constructor*/public function beforeFilter(){// 共通ヘッダー$ci =& get_instance();$ci->load->view('parts_hook/header');}/*** afterFilter - post_controller*/public function afterFilter(){// 共通フッター$ci =& get_instance();$ci->load->view('parts_hook/footer');}}
/*| --------------------------------------| Hooks| --------------------------------------| This file lets you define "hooks" …略$hook['post_controller_constructor'] = array('class' => 'ControllerCallback','function' => 'beforeFilter','filename' => 'ControllerCallback.php','filepath' => 'hooks');$hook['post_controller'] = array('class' => 'ControllerCallback','function' => 'afterFilter','filename' => 'ControllerCallback.php','filepath' => 'hooks');
public function __construct(){parent::__construct();$config =& get_config();if ($config['log_file_name'] != ''){$this->_log_file_name = $config['log_file_name'];}}
public function write_log($level = 'error', $msg, $php_error = FALSE){if ($this->_enabled === FALSE){return FALSE;}$level = strtoupper($level);if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)){return FALSE;}$filepath = $this->_log_path.$this->_log_file_name;$message = '';if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)){return FALSE;}$message .= date($this->_date_fmt).' ('.$level.') '.$msg."\n";flock($fp, LOCK_EX);fwrite($fp, $message);flock($fp, LOCK_UN);fclose($fp);@chmod($filepath, FILE_WRITE_MODE);return TRUE;}
・名前をapp/(そのままでもいいし)に変えて、web_rootとは別のとこに置く(system/とも別のとこ)
・web_rootに置く・$system_path $application_folderのパス設定
・$config['base_url'](設定しなくてもいいらしいが?)・$config['index_page'] = '';・$config['url_suffix'] = '.html';・$config['charset'] = 'UTF-8';・$config['enable_hooks'] = FALSE; ←フック使わなきゃFALSE・$config['subclass_prefix'] = 'MY_';→今は未設定 そのうち使うかも・$config['log_threshold']=0→ログを出すときは下記の設定から選ぶ→0だとログでない| 0 = Disables logging, Error logging TURNED OFF| 1 = Error Messages (including PHP errors)| 2 = Debug Messages| 3 = Informational Messages| 4 = All Messages・$config['log_path'] →ログ出す場所 フルパス→ログファイル名まで書くのかと勘違いしてた...orz→ログディレクトリパスを書く ex)$config['log_path'] = 'C:/webapp/logs/';→win環境で、¥使うとエラーになるから/スラッシュで。→指定しなければ、デフォルトのAPPPATH.'logs/'が指定される・$config['encryption_key'] セッション使うなら・Session Variables →セッションの詳細設定・Cross Site Request Forgery →このへんも必要かも(未設定)
・DBをapp全体で使うなら$autoload['libraries'] = array('database');→使いたいところで接続する手動設定とか、DSN設定とかも使えるし
・DB設定$db['default']['username'] = 'username';$db['default']['password'] = 'password';$db['default']['database'] = 'test';とか$db['default']['dbcollat'] = 'utf8_general_ci';とかね
・web_root配下に .htaccess設置(もしくはhttpd.confでもいいけど)・↓設定RewriteEngine onRewriteRule ^(.*)$ index.php/$1 [L]