2010年2月19日金曜日

phpのsettype関数にぷちはまり

久しぶりにphpにはまりました。

実は構文チェックエンジンを作成してまして、
文書中の"true""false"という文字列を、ブール型のTRUEFALSEとして評価しなきゃいけない機会が発生しました。

ここで私は、settype関数を利用しました。
settype関数は第1引数の変数を第2引数で渡した型文字列で変換するというモノです。
settype(検査したい変数, 変換させたい型)
php:settype

変換に利用できる第2引数には以下が指定できます。
(この時、文字列で指定しなければならないので、クォートします。)
"boolean" or "bool"
"integer" or "int"
"float" or "double"
"string"
"array"
"object"
"null"

今回はブール型に変換したいので"boolean"を指定します。
ですが結果は以下のようになってしまいました。
$item_true = 'true';
$item_false= 'false';

settype($item_true, 'boolean');
settype($item_false, 'boolean');

var_dump($item_true); // boolean true と表示される
var_dump($item_false); // boolean true と表示される


ここで、"boolean" を "bool" に変更しても結果は同じ・・・

そしておかしさに気づいたのですが、上記の $item_true に適当な文字列を突っ込んでみても、boolean true に変換されてしまうのです。


これはと思って以下のように変更!

$item_true = '1';
$item_false= '0';

settype($item_true, 'boolean');
settype($item_false, 'boolean');

var_dump($item_true); // boolean true と表示される
var_dump($item_false); // boolean false と表示される


やっぱり!

phpのtruefalseはdefine定義で1, 0を表しているようなもんだから、変換の時は、1,0を元に評価してしまうのですね。わかります。


元々の目的は構文チェックエンジンの作成なので、
そういうことだったら、以下の記述で十分
$item = 'true';
if($item == 'true' || $item == 'TRUE')
{
  $result = true;
}
else
{
  $result = false;
}

var_dump($result); // boolean true と表示される

2010年2月15日月曜日

厄払い



先日14日に、西新井大師まで厄払いに行ってきましたー。

本当は年始に行こうと思っていたんですが、乗り遅れちゃったので旧正月に合わせていってきました。

お札買って、おみくじも引きました。
おみくじは久しぶりの大吉です!




ただ、何となく体がだるいのはなぜでしょうか・・・風邪をもらってきたかも・・・

2010年1月21日木曜日

PEACE MAKER見た

http://新撰組peacemaker.jp/

なんか違和感。

最初はアニメ化されたときに見てたから、
実写との違和感を感じてたんだと思ってたんだけど、

それもなんか違うなぁと・・・


何が違うかっていうのがさっきわかったんだけど、
このドラマって、お腐さん向けの臭いがぷんぷんすんだよね。


ボクは歴史大好き父さんの影響で、
おっさん向けのテイストで洗脳されてるっぽい。


だから、史実は別にしても「新撰組の隊士はこんな感じ」っていう小説やドラマで
デファクトスタンダードにされている人物像がベースになっちゃって、

漫画という形で、今までの古い常識にメスをいれた上で、
さらにドラマ化っていうと、ボクの知っているものとは全く別になってる上に、
歴史物はなるべく史実に沿って欲しいなんて思ってるもんだから、
やっぱり違和感は感じるなぁ。

2010年1月8日金曜日

AirMacDiskをセットアップしてみる(裸族のインテリジェントビル)



センチュリー社の「裸族のインテリジェントビル」を購入したので早速セットアップです。


ちょっとパソコンの数が増えてきたので、数を減らして管理を楽にしようというのが目的です。


今我が家には、「ファイルサーバ」兼「テレビ録画」兼「アプリサーバ」のパソコンが一台あるのですが、

こいつの「ファイルサーバ」機能をインテリジェントビルに移し、AirPortExtremeにつなげてNASとします。
そして「テレビ録画」機能は、地デジ対応TVキャプチャを買って地デジ対応したいと思います。
※「アプリサーバ」としての機能は、以前このブログでも紹介したMacサーバに移行済みです。



まずは、現状のパソコンのデータを移します。

そもそも、今「ファイルサーバ」として活躍してくれてるパソコンの容量は、
1TBのHDDを4台使ってRAID01を構成しています。

この4台をインテリジェントビルに移してRAID10として利用します。


データ移行ですが、実質のHDD容量が2TB(計算によりますが、windowsで見ると1.8TBと出ます。そう読み取ってください)あるうち、
実際の利用領域は「旧アプリサーバで200GB」「テレビ録画で500GB」なので、1.1TBの移行になります。

その1TBのデータですが、手持ちのHDDの関係で以下のように分割退避。
・500GBHDD
・80GBHDD×2
・60GBHDD
・メインwindows機残り200GB
・Macサーバ残り250GB

という事で、社会人な僕は寝る前の時間、寝てる間、会社にいってる間の時間を使って2日間かけて移行しました。



ようやく移行が終わったら、今度は物理的なセットアップです。

今までのパソコンから取り出して、インテリジェントビルにオン!
RAIDスイッチをいれたらokです!

そしたら、今度はフォーマット。

転送速度が気になるので、eSATAでメインwindows機につなげてNTFSフォーマット。(これは、寝る前にフォーマット設定して、会社行く前が80%超えたくらいの進捗だったので、10時間くらいでおわったかな?)



次は、AirPortExtremeにつなげてデータ転送・・・



HDDが見つからない・・・



AirPortのマニュアルを見ると認識されるとAirMacディスクユーティリティーに認識されると書いてあるけど、全然認識されない。


ではMacでは?
認識される・・・が、書き込めない!


なんで!?


あ、MacはHFSだ!


そんな訳で、HFSで再びフォーマット。
(実はNTFSにフォーマット後に、退避したデータを半分近く戻したので、再退避に1日つかいました・・・(;ω;))



今度は、Macで認識・・・できる!


windowsで認識・・・できない!

AirMacディスクユーティリティーでログインしようとしても・・・




というエラー。


これは、とっさの思いつきで回避できたのだけれども、
AirPortルータのアドレスを指定するとアクセスが可能です。

ただ、設定の度に時間かかるのがいやなので試してないけど、
AirMacディスクユーティリティーが必要だったのかはわからない・・・

2009年12月13日日曜日

xdebugインストール

xdebugはpeclでインストールする。

peclは別個で入れるかどうかするのですが、SuSEユーザの私は「php-devel」をインストールしたときに自動的に入ります。

それで早速コマンド
# pecl install xdebug
downloading xdebug-2.0.5.tar ...
Starting to download xdebug-2.0.5.tar (Unknown size)
...............................................................................................................................................................................................................................................................done: 1,340,928 bytes
67 source files, building
WARNING: php_bin /usr/bin/php5 appears to have a suffix 5, but config variable php_suffix does not match
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:3555: AC_LIBTOOL_LINKER_OPTION is expanded from...
aclocal.m4:5493: _LT_AC_LANG_C_CONFIG is expanded from...
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
aclocal.m4:2972: AC_LIBTOOL_SETUP is expanded from...
aclocal.m4:2952: _AC_PROG_LIBTOOL is expanded from...
aclocal.m4:2915: AC_PROG_LIBTOOL is expanded from...
configure.in:150: the top level
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:3510: AC_LIBTOOL_COMPILER_OPTION is expanded from...
aclocal.m4:7620: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:5606: _LT_AC_LANG_CXX_CONFIG is expanded from...
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
aclocal.m4:4641: _LT_AC_TAGCONFIG is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:3555: AC_LIBTOOL_LINKER_OPTION is expanded from...
aclocal.m4:5493: _LT_AC_LANG_C_CONFIG is expanded from...
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
aclocal.m4:2972: AC_LIBTOOL_SETUP is expanded from...
aclocal.m4:2952: _AC_PROG_LIBTOOL is expanded from...
aclocal.m4:2915: AC_PROG_LIBTOOL is expanded from...
configure.in:150: the top level
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:3510: AC_LIBTOOL_COMPILER_OPTION is expanded from...
aclocal.m4:7620: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:5606: _LT_AC_LANG_CXX_CONFIG is expanded from...
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
aclocal.m4:4641: _LT_AC_TAGCONFIG is expanded from...
building in /var/tmp/pear-build-root/xdebug-2.0.5
running: /tmp/pear/temp/xdebug/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... no
checking for gcc... no
configure: error: in `/var/tmp/pear-build-root/xdebug-2.0.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
ERROR: `/tmp/pear/temp/xdebug/configure' failed

cc、gccがないからコンパイルできないぞ・・・と


yastでcc、gccをインストールして再実行。
# pecl install xdebug
downloading xdebug-2.0.5.tar ...
Starting to download xdebug-2.0.5.tar (Unknown size)
...............done: 1,340,928 bytes
67 source files, building
WARNING: php_bin /usr/bin/php5 appears to have a suffix 5, but config variable php_suffix does not match
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:3555: AC_LIBTOOL_LINKER_OPTION is expanded from...
aclocal.m4:5493: _LT_AC_LANG_C_CONFIG is expanded from...
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
aclocal.m4:2972: AC_LIBTOOL_SETUP is expanded from...
aclocal.m4:2952: _AC_PROG_LIBTOOL is expanded from...
aclocal.m4:2915: AC_PROG_LIBTOOL is expanded from...
configure.in:150: the top level
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:3510: AC_LIBTOOL_COMPILER_OPTION is expanded from...
aclocal.m4:7620: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:5606: _LT_AC_LANG_CXX_CONFIG is expanded from...
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
aclocal.m4:4641: _LT_AC_TAGCONFIG is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:3555: AC_LIBTOOL_LINKER_OPTION is expanded from...
aclocal.m4:5493: _LT_AC_LANG_C_CONFIG is expanded from...
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from...
aclocal.m4:2972: AC_LIBTOOL_SETUP is expanded from...
aclocal.m4:2952: _AC_PROG_LIBTOOL is expanded from...
aclocal.m4:2915: AC_PROG_LIBTOOL is expanded from...
configure.in:150: the top level
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:3510: AC_LIBTOOL_COMPILER_OPTION is expanded from...
aclocal.m4:7620: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from...
configure.in:150: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, ...): suspicious cache-id, must contain _cv_ to be cached
aclocal.m4:5606: _LT_AC_LANG_CXX_CONFIG is expanded from...
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from...
aclocal.m4:4641: _LT_AC_TAGCONFIG is expanded from...
building in /var/tmp/pear-build-root/xdebug-2.0.5
running: /tmp/pear/temp/xdebug/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib64/php5/extensions
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... gawk
checking whether to enable eXtended debugging support... yes, shared
checking for gettimeofday... yes
checking for cos in -lm... yes
checking for ld used by cc... /usr/x86_64-suse-linux/bin/ld
checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes
checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc static flag works... yes
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
sh: make: command not found
ERROR: `make' failed


あれ、makeもはいってなかった・・・


makeもインストールして、再実行!
Build process completed successfully
Installing '/usr/lib64/php5/extensions/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.0.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=xdebug.so" to php.ini


最後だけ抜粋ですがokのようです。
# service apache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate) done
Starting httpd2 (prefork) done



phpinfoで確認してok

pear.php.net is using a unsupported protocal - This should never happen.

最近Macサーバに移行してから、プログラム類や開発関係のデータもちょっとずつ
移行させているのですが、「あ、xdebug入れてない」と思って、導入開始しました。

たしか、peclかなんかのコマンドで行けるんじゃなかったっけ?
と思って、pearコマンドでインストール開始。

でも、xdebugとは別に以下のエラーが出てしまいました。

pear.php.net is using a unsupported protocal - This should never happen.

これはインストール以前の問題ですね。

プロトコルアンサポート・・・

とりあえずチャンネルを更新しようとおもって、以下のコマンド実行
# pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date


あれ、こんなんだっけ?

再度、xdebugインストール実行
# pear install xdebug
pear.php.net is using a unsupported protocal - This should never happen.
install failed



だめだ・・・



それでエラーコードを検索していたら、pearのblogで原因判明!
http://blog.pear.php.net/2009/08/28/fixing-unsupported-protocol/
5.2.10と5.2.11が対象って書いてあるけど、5.3.0も対象ね。


以下、pearのblogより抜粋で実行
# cd `pear config-get php_dir`
# mv .channels .channels-broken
# pear update-channels

どうにもチャンネルデータが壊れているので、消して(もしくは移動して)再取得すればいいみたい。

3行目の「pear update-channels」でチャンネルデータ再取得でok

うちは、タイムゾーンの設定不備で以下のエラーも出ちゃったけど、チャンネル更新はok
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in PEAR/Registry.php on line 930
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /usr/share/php5/PEAR/PEAR/Registry.php on line 930

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in PEAR/Registry.php on line 930
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /usr/share/php5/PEAR/PEAR/Registry.php on line 930

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in PEAR/Registry.php on line 930
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /usr/share/php5/PEAR/PEAR/Registry.php on line 930
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded

succeededってでてるのでok


今度こそxdebugインストール!
# pear install xdebug
No releases available for package "pear.php.net/xdebug" - package pecl/xdebug can be installed with "pecl install xdebug"
install failed

peclでやれと・・・

2009年12月11日金曜日

svn: Can't open fileエラー

svnサーバにコミットしたところ以下のようなエラーが返ってきてしまった。

svn: Can't open file '/var/svn/hogehoge/db/txn-current-lock': Permission denied
svn: MKACTIVITY of '/repos/hogehoge/!svn/act/069d9079-2501-0010-a783-df4e102faed0': 500 Internal Server Error (http://hogehoge.com)


というようなエラーが出てしまった・・・

Permission deniedということから、パーミッション設定がよくないらしい・・・


確認してみると、オーナーがrootになってました。

apache2のmod_davでsvnを利用している以上、apache2が操作できる権限にしておかなきゃね。