くまきち

山と旅と家族が大事。
でも激しい物欲が理性と財布のタガを飛ばす
最近は自転車も乗ってる

[PHP][PDF]Haruを使ってみる(1)

2013-05-30 09:36:30 | SEまわり
PHP からの PDF 生成について、よさげなライブラリが紹介されていたので試してみた。


 【Haruで基本的なPDFを作成する(CodeZine)】
   http://codezine.jp/article/detail/7141]

まずは libharu のインストールから。

参考ページでは yum でインストールしているが、手元の環境ではできなかったので、ソースからインストールした。

wget http://libharu.org/files/libharu-2.1.0.tar.gz
tar xfz libharu-2.1.0.tar.gz
cd libharu-2.1.0
./configure
make
make install

続いて Haru のインストール。

最初、プロキシ設定がなかったため、pecl config-set http_proxy <proxy> としてみたけどダメだった。 pecl じゃなくて、pear でよかったみたい。

以下、実行時のログ。

pecl install haru
downloading haru-1.0.4.tgz ...
Starting to download haru-1.0.4.tgz (27,538 bytes)
....done: 27,538 bytes
4 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Please provide the prefix of libharu installation [autodetect] :
building in /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4
running: /tmp/pear/temp/haru/configure --with-haru
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /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/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for Haru PDF support... yes, shared
checking for the location of libz... no
checking for the location of libpng... no
checking for Haru in default path... found in /usr/local/
checking for HPDF_Stream_WriteToStreamWithDeflate in -lhpdf... yes
checking for HPDF_LoadPngImageFromFile in -lhpdf... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/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 recognize 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... 1966080
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 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 static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/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
/bin/sh /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/libtool --mode=compile cc -I. -I/tmp/pear/temp/haru -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/include -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/main -I/tmp/pear/temp/haru -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local//include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/haru/haru.c -o haru.lo
mkdir .libs
cc -I. -I/tmp/pear/temp/haru -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/include -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/main -I/tmp/pear/temp/haru -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local//include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/haru/haru.c -fPIC -DPIC -o .libs/haru.o
/bin/sh /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/include -I/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/main -I/tmp/pear/temp/haru -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local//include -DHAVE_CONFIG_H -g -O2 -o haru.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules haru.lo -Wl,-rpath,/usr/local//lib -L/usr/local//lib -lhpdf -lpng -lz
cc -shared .libs/haru.o -Wl,--rpath -Wl,/usr/local/lib -Wl,--rpath -Wl,/usr/local/lib -L/usr/local//lib /usr/local/lib/libhpdf.so -L/usr/lib -lpng -lz -Wl,-rpath -Wl,/usr/local//lib -Wl,-soname -Wl,haru.so -o .libs/haru.so
creating haru.la
(cd .libs && rm -f haru.la && ln -s ../haru.la haru.la)
/bin/sh /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/libtool --mode=install cp ./haru.la /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules
cp ./.libs/haru.so /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules/haru.so
cp ./.libs/haru.lai /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules/haru.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules
----------------------------------------------------------------------
Libraries have been installed in:
/tmp/pear/temp/pear-build-rootXsIh94/haru-1.0.4/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4" install
Installing shared extensions: /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib/php/extensions/no-debug-non-zts-20100525/
running: find "/tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4" | xargs ls -dils
74 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4
95 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr
96 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local
97 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib
98 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib/php
99 4 drwxr-xr-x 3 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib/php/extensions
100 4 drwxr-xr-x 2 root root 4096 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib/php/extensions/no-debug-non-zts-20100525
94 300 -rwxr-xr-x 1 root root 307054 5月 30 08:51 2013 /tmp/pear/temp/pear-build-rootXsIh94/install-haru-1.0.4/usr/local/lib/php/extensions/no-debug-non-zts-20100525/haru.so

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/haru.so'
install ok: channel://pecl.php.net/haru-1.0.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=haru.so" to php.ini

最後のところに、php.ini の extension に指定をするように指示がある。

言われたとおりにして、httpd を再起動。

インストールは終わり。

Windows7/64 で FreeMind が起動できない

2013-05-29 13:05:49 | SEまわり
アイデアを整理するときには、FreeMind をよく使っている。
といっても月に1度程度だけど。

今日使おうと、起動したら何も言わずに終了する。
エラーも何もない。

Windows の更新プログラムがその前に当たっていたから、何か変化があったせいかもしれないと、再起動してみたけど変化なし。

Java の環境を確認すると、これ。 大丈夫だ。問題ない(実はこれがウソ)




FreeMind をいったんアンインストールし、再インストールしてみることにした。
インストーラを起動すると、このエラーが出る。



Java が見つからないとのこと。
Path の値に Java の位置を明示的に指定したけどダメ。

原因は、JRE が 64bit 版だったため。

前は 32-bit 版(OS は Windows7 64bit)を入れていたと思ったが、いつのまにか変えてたのかもしれない。

32bit 版の JRE をインストールしたら、無事に起動した。

ややこしい。


それにしても、すごく久しぶりに windows の環境変数 Path の中を見た気がする。
恐ろしく長い。

これ何文字くらいまで行けるのかな。
MS-DOS の頃には制限があって、収めるためにディレクトリ名を短くしたりした記憶があるんだが。

何にしろ、Program Files とか無駄に長いパス使うから見づらくなるんだよ。
どうにかならんのかな。

[自転車][国東] グランフォンド前最後のトレーニング

2013-05-28 18:35:05 | 自転車
一昨日 (5/25(土))、ゴールデンウィークにインフルエンザにかかってツール・ド・くにさきを欠場して以来、まともにトレーニングをしてなかったが、さすがに一度は100km超を走っておかないと体もバイクも不安と言うことで、会社の先輩らと一緒に国東半島を一周してきた。

スタートは「道の駅くにさき」

ここからだいたい国道を南下して杵築から山香に抜け、10号線に出たら宇佐まで進み、再び213号線に折れて豊後高田、国見、国東に戻ってくるルート。


昼食は山香町にある「山ちゃん」でカツ丼。

昔仕事で近くに来てたときは必ずここで食ってた。




コースはアップダウンが少ないが、豊後高田を過ぎて海岸線に沿って走るところでは小さいものが連続する。
トレーニングとしてはとてもいいんだが、左膝が珍しく軋んでて、調子が上がらず。 正直言って疲れた。

わりとへろへろになりながら、道の駅くにみ へ到着。 タコが名物なのかな。



ここでしっかり水分、エネルギーを補給したあとは膝の調子も良くなり、それにひっぱられて体調も復活。再び強く踏み込めるようになった。
ひどい向かい風の中スタート。

あと 20km しっかりトレーニングだと こいでたら、残り 11km でアクシデント発生。

同行の1名がキャットアイ踏んづけて転倒。あちこちに擦過傷を作って、打ち身もあり、バイクやシューズも破損。
ただ、骨折や裂傷は見られず不幸中の幸い。 ケガ慣れ?

パンクもしてたので、その修理とバイクの補修を済ませたら再スタート。


ツール・ド・くにさきのエイドステーションに使われたという広場で最後の休憩。
景色が良い。




最後のあたりはサイクリングロードを初めて走ったんだけど、川や港に何度も分断されたり、道が分からなくなったりして困った。
でも、こういうのが整備されているのは有り難い。


[自転車][グランフォンド軽井沢] キット到着

2013-05-27 23:50:15 | 自転車
グランフォンド軽井沢のキットが届いた。

グランフォンドは去年に続いて2度目、その前はグルメフォンドに出たから、軽井沢は都合3年目3回目。



準備不足&天候が怪しい という状況。 どこまでいけるかな。


バイクは本日先輩の手によって東京へと運ばれていった。 グランフォンド当日までしばしのお別れ。

[PostgreSQL] pgFouine を使ってボトルネックを探してみる

2013-05-27 20:14:04 | SEまわり
PostgreSQL サーバ上でボトルネッククエリを見つけたくて pgFouine を使ってみた。

本来ならスムーズに動きそうなもんだが、ちょっとハマったのでメモを残す。

まずは、インストール 。
本家サイト からダウンロードして、どこでもいいので展開。

 
tar xfz pgfouine-1.2.tar.gz


以上。

あとは動かすだけなんだが、syslog 出力したログを取り込むのが前提なので、あらかじめ PostgreSQL の設定をそのようにしておくこと。

また、ログフォーマットにも指定がある。
最後のシングルクォートの前には空白が入っているので注意。

 
log_line_prefix='%t [%p]: [%l-1] '


このようにしておくこと。

で、最後のポイント。これにつまづいた。

ロケール指定がないこと。

initdb するときに --no-locale を指定するのは世界のお約束だが、やってないシステムでは postgresql.conf にて、以下の指定が要る。

 
lc_message='C'


これが 'ja_JP.UTF-8' なんて値になっていると、pgFouine は文句を吐きまくって、しまいには「有効なログが一行もないよ」と怒って終了する。

ロケール設定とか何につかうねん。


あとは、こうやって出力したログを次のように指定して実行すれば、結果 HTML が標準出力に出てくるので、ファイルに書き出すなりして見る。

 
./pgfouine.php -file /var/log/pgsql.log


以上。


ちなみに、pgfouine って、どう読めばいいんだろう。

[蒲田] 自転車部会合

2013-05-24 08:12:26 | 自転車


手頃な名目があり、蒲田で自転車部集合。
11人も集まった。

会社も勤務地も違うし、住まいも首都圏やら九州やらに分散しているけど、いつのまにか仲間がずいぶん増えた。

来週末のグランフォンド軽井沢の段取り確認や、体力的な準備が進んでたり進んでなかったりといった状況も共有して、あとは飲み放題食い放題。
体調管理もあるので珍しく2軒目には行かずに解散。

【金春新館】
http://r.gnavi.co.jp/b706900/

グランフォンド軽井沢2013

2013-05-18 23:15:23 | 自転車
大分に転勤で戻ってしまったのと、今年は夏にトルコのアララト山に行こうとしていることから、参加を見送っていたグランフォンド軽井沢。

 【グランフォンド軽井沢】
  http://fm-karuizawa.net/granfondo/

参加できない理由の中心は費用だったんだけど、東京の自転車仲間がいろいろ算段をしてくれて、蒲田に前泊して、日曜早朝からの日帰り参加することになった。

自転車を前週に東京に運んでくれるひとがいたり、そこから軽井沢へも前日のうちに運んでくれるひとがいたり。。。

そこまでしてくれるというのに、大分で黙って座ってるわけにはいかないでしょ。

という説得で家族も納得してくれて、期限ぎりぎりでエントリーした。


今年は早めに申し込むと参加料が安くなる「早割」があったけど、それには間に合わなかった。

申し込んだらすぐに航空券手配、ホテル確保(終わって東京に戻ってきてから1泊しないといけない)、職場への有給申請(大分に戻る)を済ませ、無事に準備は整った。

あとは当日に向けたトレーニングと体調管理。
どうも春先に走った頃から、筋力が弱ってるんじゃないかと思うところがあり、要注意。
あとちょうど2週間、できるだけ体を作っていくつもり。


これは去年。
どっかに写ってます。


[大分市] 歩道橋がなくなる

2013-05-16 13:32:59 | 雑記
大分市中心部にある四辺形の歩道橋、バリアフリー化とかでなくなるそうだ。

知ったときにはすでに封鎖されてしまっていた。

上から見る、大分では大きな通りの交差点。 眺めるのが好きだったが、もうできない。
早くから知っていれば、いろいろな時間帯に写真を取っておきたかった。 残念だ。

今はどんどん階段部分を撤去していってるようで、ちょうど昨夜はそこを通りかかった。


Canon EOS 6D / EF40mm F2.8 STM / f5.6 1/40sec

裏駅(今やそっちが【表】っぽいけど)も、以前とは大きく様変わりしてて面食らう。

あちこち景色が変わっていくのは、寂しい感じがするなあ。


それはそうと、何も気にせずに感覚だけで撮ってこのレベルってのは、すごいな 6D。

[CakePHP] 共通関数ファイルなどの読み込み

2013-05-16 13:25:47 | SEまわり
最近になってようやく CakePHP の 2系を使うようになった。

ディレクトリ名先頭が大文字になっているのは、感覚的には好きだけど Shift キーを押すのが面倒。

基本的な使い方をする範囲では、1系とさほど変わらないように感じる。

で、共通関数ファイルを1系のやつから持ってきて食わせようとしたんだけど、bootstrap.php の中身が増えてた。
いろいろできるようになってるが、したいことはファイル読み込みだけなので、

 config('functions');


で終わり。 Config/function.php がインクルードされる。

でも、これってマニュアル(Cookbook)のどこに書かれているのかは見つけられなかった。

どこにあるんだ?