imodeで301ステータスがでてリダイレクトしてしまう原因

imode(ドコモ)のみ 「サイトが移動しました(301)」
と出る場合は、リンクの書き方を疑ってみると吉
一階層下のhogeフォルダに移動する場合
<a href=”hoge”>hogeフォルダに移動</a>
としていると、301になる。
<a href=”hoge/”>hogeフォルダに移動</a>
と、最後にきちんと /(スラッシュ)を付けるのが正解。
おそらく、サーバ側で自動で/(スラッシュ)を補完している挙動の部分を拾っているみたい。

ssl imode ドコモ docomo 画像 再呼び込み 通信 KeepAlive 連続

訳の分からないタイトルですが、
imode で、SSLのページにおいて、何度もSSL通信をしてしまう現象が
おきた場合は、
apache の設定の
KeepAlive の所を見直す、とたぶん Offになっているので、ここをOnにする
KeepAlive Off
から
KeepAlive On
ですね、なかなか検索しても出てこないので、タイトルをなんとなく
検索キーワードに近づけてみました。
http://www.bitwin.ne.jp/blog/?p=3
とかに詳しくかいてます。
http://www.nttdocomo.co.jp/service/imode/make/content/ssl/flow/

* Keep-Aliveする場合の動作
最初の画面だけハンドシェイク(次回以降、暗号化通信のみ)
* Keep-Aliveしない場合の動作
毎画面表示のたびにハンドシェイク
と書いてあるので、この現象が起きてた状態ですね。

2009.08.06

Category: PHP / Tags: ,

phpの try and catch のサンプル

挙動の確認の為のサンプル
ini_set("display_errors","on");
class a
{
function aa()
{
$bool = false ;
if($bool){
//何かの処理
}else{
throw new Exception('error message');
}
}
}
class b extends a
{
function bb()
{
try{
$a = new a();
$a->aa();
}catch(Exception $e){
throw $e ;
}
}
}
class c extends b
{
function cc()
{
try{
$b = new b();
$b->bb();
}catch(Exception $e){
$this->_catchError($e);
}
}
function _catchError($e)
{
$error = “”;
$error .= “
\n”;
$error .= “Catch error in “. $e->getFile() . “ on line ” . $e->getLine() . “
\n”;
$error .= $e->getMessage() . “
\n”;
$error .= “trace
\n”;
$trace = $e->getTrace();
foreach($trace as $key => $val){
$error .= ““. $val['file'] . “ on line ” . $val['line'] . “
.” in class = {$val['class']}”
.”, function = {$val['function']}”
.”, type = {$val['type']}”
.”, function ={$val['function']}”
// .”, args = ” . print_r($val['args'])
. “
\n”
;
}
print_r($e);
print $error ;
       // mailが飛べば本番も安心だね
// mail(’admin@ecamlpe.com’,'php error’, $error);
}
}
$c = new c();
$c->cc();

2009.07.28

Category: Redhat ES(CentOS) / Tags:

networkの設定 ifconfig でIPアドレスを割り当てる

  ・FreeBSD

コマンドラインによる設定
# ifconfig fxp0 inet IPアドレス netmask 255.255.255.255 alias
設定ファイルへの記述(以下の1行を追加設定)
# vi /etc/rc.conf
ifconfig_fxp0_alias1 inet IPアドレス netmask 255.255.255.255

  ・RedHat/Fedora/CentOS Linux

コマンドラインによる設定
# ifconfig eth0:0 inet IPアドレス netmask 255.255.255.255
設定ファイルへの記述(以下のファイルを新規作成)
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=none
ONBOOT=yes
IPADDR=IPアドレス
NETMASK=255.255.255.255

設定一覧は
# ifconfig
で確認できます。
inet オプションは、 ipv4の事(デフォルト)
複数割り当てる場合は、「etho:1」とか名前をかえて設定していくこと。

2009.07.16

Category: PHP / Tags:

自分メモ 配列と文字列の切り替え

/**
* 文字列を配列に変換 (ここに有るべきでない)
* @parame $str string 配列になるべき文字列_(アンダースコア)つなぎ
* @return array _(アンダースコア)をデミタリにされた配列
*/
function getStrToArray($str)
{
$ary = explode( “_”, substr($str,1,-1) );
$a = “”;
if( is_array($ary) ){
foreach( $ary as $value ){
$a[] = $value ;
}
}
return $a ;
}
/**
* 配列を文字列に変換 (ここに有るべきでない)
* @parame array _(アンダースコア)をデミタリにされた配列
* @return $str string 配列になるべき文字列_(アンダースコア)つなぎ
*/
function getArrayToStr($ary)
{
if( is_array($ary) ){
$str = “_”. implode(”_”,$ary) . “_” ;
}else{
$str = “__”;
}
return $str ;
}

2009.04.17

Category: PHP / Tags:

Hyper Estraier を phpからつかってみる(検索のみ)

http://page2.xrea.jp/
に、ノード API の Pure PHP クラスライブラリ EstraierPure があったので、これを利用して
Hyper Estraier をつかってみる。
でだしは、MTの検索が重いので、全文検索のnamazuを利用していたのだけど、つかいこなして
ないこともあって、いまいち検索結果がピンとこない。
てことで、文章ドラフトをつくれる、Hyper Estraierで、やってみようかとというところと,
PHP Namazu モジュールでは、URIを指定しての検索ができない(つまりはブロガー指定の検索ができない)ので、

一応、Cのソースまで見てみたのですが、実装ができてないみたいだったので、できるならごめんなさい。
自分で実装すれば、っていうのも今回はなしで。

P2Pあたりの機能で実装できそうなこちらにチャレンジしてみます。
ブログ登録があると自動で検索対象にしてくれるモジュールがあるのも決めてでした。
namazuだと、毎日indexの更新するcronが動くまでまたないといけなかったので。
下記にドキュメントはあるのですが
http://page2.xrea.jp/doc/all/index.php?package=Services_HyperEstraier
多くの人がとりあえず、indexの生成とかは、サーバーがわのシェルスクリプトとかでやって
検索インターフェイスの実装だけをしたいと思うので、(というかおいらが)その分のメモ書き
現状の検索は
html -> js(ajax) -> api -> namazu -> api -> js -> html
のながれで、jsから、apiにアクセスして、apiが内部でnamazuの検索結果を取得して、XML
に変換して返しているので、この aip の書き直しと namazuを hyper estraier への移行で
対応したいと思います。
Class HyperEstraier_Condition が検索で主に使われるクラスになります。
簡単なながれで、
1.検索のオプション値(検索ワード、表示順、取得数)を設置して、
2.検索メソット(serach)にアクセスして、結果を取得
3.取得したデータを加工して表示
  (xmlでも結果を取得できるので上手くいけばいらないかもしれない)
を想定
HyperEstraier_Conditionの初期値(つまりは、検索の初期値)は、下記の通り
//初期値
$this->phrase = null;
$this->attrs = array();
$this->order = null;
$this->max = -1;
$this->skip = 0;
$this->options = 0;
$this->auxiliary = 32;
$this->distinct = null;
$this->mask = 0;
それぞれ、setterとgetterのメソットがあるので、あとはそれらを利用して自由に検索してください。
簡易一覧 – そのうち適当な日本語に置き換える予定
function_name param の順です
//Set the search phrase.
set_phrase($phrase) (string $phrase A search phrase.) void
//Add an expression for an attribute.
add_attr($expr) (string $expr A search expression.) void
//Set the order of a condition object.
set_order($order) (string $order An expression for the order. By default, the order is by score descending.) void
//Set the maximum number of retrieval.
set_max($max) (int $max The maximum number of retrieval. By default, the number of retrieval is not limited.) void
//Set the number of documents to be skipped.
set_skip($skip) (int $skip The number of documents to be skipped. By default, it is 0.) void
//Set options of retrieval.
set_options($options) (int $options Options: * – ESTRAIERPURE_CONDITION_SURE’ specifies that it checks every N-gram key. * – ESTRAIERPURE_CONDITION_USUAL’, which is the default, * specifies that it checks N-gram keys with skipping one key. * – ESTRAIERPURE_CONDITION_FAST’ skips two keys. * – ESTRAIERPURE_CONDITION_AGITO’ skips three keys. * – “ESTRAIERPURE_CONDITION_NOID” F’ specifies not to perform TF-ID F tuning. * – ESTRAIERPURE_CONDITION_SIMPLE’ specifies to use simplified phrase. * – ESTRAIERPURE_CONDITION_ROUGH’ specifies to use rough phrase. * – ESTRAIERPURE_CONDITION_UNION’ specifies to use union phrase. * – ESTRAIERPURE_CONDITION_ISECT’ specifies to use intersection phrase. * Each option can be specified at the same time by bitwise or. * If keys are skipped, though search speed is improved, the relevance ratio grows less.) void
//Set permission to adopt result of the auxiliary index.
set_auxiliary($min) (int $min The minimum hits to adopt result of the auxiliary index. If it is not more than 0, the auxiliary index is not used. By default, it is 32.) void
// Set the attribute distinction filter.
set_distinct($name) (string $name The name of an attribute to be distinct.) void
//Set the mask of targets of meta search.
set_mask($mask) (int $mask A masking number. 1 means the first target, 2 means the second target, 4 means the third target, and power values of 2 and their summation compose the mask.) void
// getter methods
それぞれのgetter methods
function phrase()
function attrs()
function order()
function max()
function skip()
function options()
function auxiliary()
function distinct()
function mask()

上記の、設定がおわったら
EstraierPure_Node の search メソットになげれば、検索結果(EstraierPure_NodeResultのobject)が返ってきます。
get_doc
get_doc_attr
get_doc_attr_by_uri
get_doc_by_uri
あたりをつかって、加工すればOK

2009.04.01

Category: PostgreSQL / Tags:

postgreSQLでDBのサイズを確認したい場合

vacuumedb -f (full) は、できないけど、DBの再利用領域は知りたい場合
pg_database_size と pgstattuple (contribにあります) の2つのコマンド
を使うといい
使い方は、DBに入って、
dbname=# select pg_database_size(’databasename’);
pg_database_size
——————
49801171592
dbname=#select * from pgstattuple(’tablename’);
table_len | tuple_count | tuple_len | tuple_percent | dead_tuple_count | dead_tuple_len | dead_tuple_percent | free_space | free_percent
————+————-+————+—————+——————+—————-+——————–+————+————–
1738309632 | 9737154 | 1466581672 | 84.37 | 0 | 0 | 0 | 222155348 | 12.78
(1 row)
とかでてきます、大切なのは、free_spaceの所の値、ここが再利用領域になります。
– 以下に pgstattuple のREADME( 2002/08/22 石井達夫)をつけておきます。
1. pgstattupleとは
pgstattupleは,UPDATEやDELETEで作られたテーブルのゴミ領域の大きさを,
テーブル自体の物理的な大きさに対するパーセンテージで返却します.つ
まり,返却値が大きければ,それだけゴミも多いので,vacuumをかける必
要があるという判断の助けになるわけです.これ以外にもいろいろな情報
が返ります.
test=# \x
Expanded display is on.
test=# select * from pgstattuple(’pg_proc’);
-[ RECORD 1 ]——+——-
table_len | 458752
tuple_count | 1470
tuple_len | 438896
tuple_percent | 95.67
dead_tuple_count | 11
dead_tuple_len | 3157
dead_tuple_percent | 0.69
free_space | 8932
free_percent | 1.95
各項目の説明です.
table_len – テーブルの物理的な大きさ(バイト)
tuple_count – タプル数
tuple_len – タプル長の合計(バイト)
tuple_percent – タプルの割合.table_lenに対するtuple_lenの比率.
dead_tuple_len – デッドタプル数
dead_tuple_percent – デッドタプルの割合.table_lenに対するtuple_lenの比率.
free_space – 再利用可能な領域(バイト)
free_percent – 再利用可能な領域.table_lenに対するfree_spaceの比率.
2. pgstattupleのインストール
PostgreSQLが/usr/local/pgsqlにインストール済であり,testデータベー
スにpgstattupleをインストールする場合の手順を示します.
$ make
$ make install
ユーザ定義関数を登録します.
$ psql -e -f /usr/local/pgsql/share/contrib/pgstattuple.sql test
3. pgstattupleの使い方
pgstattupleの呼び出し形式は以下です.
CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type
AS ‘MODULE_PATHNAME’, ‘pgstattuple’
LANGUAGE ‘c’ WITH (isstrict);
第一引数: テーブル名
関数の戻りはpgstattuple_type型です.
pgstattupleはテーブルにAccessShareLockしかかけないので,
pgstattuple を実行中に該当テーブルに更新や削除が発生すると,正しく
ない結果を返す可能性があります.
pgstattupleがタプルを「ゴミ」と判断する基準は,
HeapTupleSatisfiesNow()が偽を返したときです.
4. pgstattupleのライセンス条件について
pgstattuple.cの冒頭に書いてある通りです.また,pgstattuple は完全に無保
証です.pgstattuple を使用したことによって生じるいかなる結果に関して
も責任を負いません.
5. 改訂履歴
2002/09/04
SRF変更に伴い,Tom Lane が修正インターフェイスの修正を行った.
そのことをこのREADMEにも反映.
2002/08/23
SRF(Set Returning Function)を使って7.3用に書き換え.
2001/12/20 Tom Laneによる修正
Fix pgstattuple to acquire a read lock on the target table. This
prevents embarassments such as having the table dropped or truncated
partway through the scan. Also, fix free space calculation to include
pages that currently contain no tuples.
2001/10/01 PostgreSQL 7.2 用contrib moduleに登録
2001/08/30 pgstattuple バージョン 0.1リリース

2009.03.18

Category: Os / Tags:

Amazon EC2 VirtualHosts の設定ではまる。(vhost, vhosts)

amazon のEC2でvertualhostの設定をしたところ、半日はまってしまった。
ec2は、 Elastic IPという固定IPが、(現時点で) EC2のインスタンス1つにつき1つもらえるので
それを元に、(頂いたIPが 111.222.333.444 とする)

NameVirtualHosts 111.222.333.444:80
<VirtualHost 111.222.333.444:80>
ServerName www.example.com
DocumentRoot “/var/www/vhosts/”
</VirtualHost>
<VirtualHost 111.222.333.444:80>
ServerName www2.example.com
DocumentRoot “/var/www/vhosts/”
</VirtualHost>

として、 www.exampel.com www2.exampel.com を立ち上げようとしても上手く行かない
VirtualHostの中のDocumentRootを見に行っってくれないのである
#apachectl -t -D DUMP_VHOSTS
でやっても、エラーも無く返ってくるのであるが上手く行かない。で正解は

NameVirtualHosts *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "/var/www/vhosts/"
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot "/var/www/vhosts/"
</VirtualHost>

とすると、うまくいく。つまりはワイルドカードを使ってしまえって事。
たぶん、仮想化の仕組み上、Elastic IPとサーバーは結びついてはいるものの
内部の設定ファイルに Elastic IPを書いても上手い事行かないんじゃないかと勝手に想像しています。
4時間も使ってしまったよ・・・。

2009.03.09

Category: MySql / Tags:

MySqlでconnect error 繋がらない場合にチェックするところ

phpとかから、 mysql_connect で繋がらない場合、チェックするところ
1. mysql自体のアクセス制限は大丈夫か?

  • ユーザの確認
  • パスワードの確認
  • ホストの確認

2.サーバー自体のアクセス制限はだいじょうぶか?

  • iptableの確認
  • selinux確認 getenforce コマンド

3. socketは同じ物をみにいっているか

  • mysql.sockの場所の確認
  • my.conf php.ini の確認
  • パーミッションの確認

dns named 設定

dns の設定
正直よくかってないので、正確な情報と思わないでください。
pictnotes.jp の DNSを設定するとしたら
当然 namedは動いている事
# /etc/init.d/named status
# cd /var/named/chroot/var/named
ファイルがないと思うので作成
# touch pictnotes.jp.rev
# touch pictnotes.jp.zone
正引き、逆引きファイルを作成
# vi pictnotes.jp.rev
—-ここから
$TTL 86400
@ IN SOA ns.pictnotes.jp. root.pictnotes.jp. (
2008121701; Serial
3H ; Refresh
15M ; Retry
1W ; Expire
1D ) ; Minimum
;
IN NS ns.pictnotes.jp.
;
IN PTR ns.pictnotes.jp.
IN PTR pictnotes.jp.
—-ここまで
—-ここから
$TTL 86400
@ IN SOA ns.pictnotes.jp. root.pictnotes.jp. (
2008121701; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
;
IN NS ns.pictnotes.jp.
IN NS ns.example.com.
IN A 202.218.112.41
IN MX 10 pictnotes.jp.
;
ns IN A 202.128.112.41
www IN A 202.218.112.41
IN MX 10 www
—-ここまで
; からあとはコメント
Serialは、修正したら新しくしなければならない、だいたい日付と連番
ドメイン登録情報のプライマリーDNSに、 ns.pictnotes.jpとIPと登録
IN NS ns.example.com.
は、セカンダリーDNS
named-checkzone
named-checkconf
等のコマンドで、構文をチェックできる。

« Older Entries   Newer Entries »