PEARをローカルにインストール

Manual :: 共有ホストでの PEAR のローカルコピーのインストール

既にpearコマンドが利用可能な場合。

$ pear config-create /path/to ~/.pearrc

/path/to/pear以下に諸々配置される設定ファイルが~/.pearrcとして作成される。
この場合、PEARディレクトリは/path/to/pear/phpとなる。

ディレクトリ等、設定をを変更したい場合は、通常通りpear config-setコマンドで。

phpコマンドを実行する際にinclude_pathの設定をしたいが、オプションでは指定できないので、php.iniを別途準備し読むように指定するaliasを設定。

$ cp /etc/php.ini /path/to
$ vim /path/to/php.ini
$ alias php='php -c /path/to/php.ini'

php.iniのinclude_pathの設定は以下のようにローカルのPEARディレクトリしか読み込まない、または、優先的に読み込むように設定。

include_path = ".:/path/to/php"
#include_path = ".:/path/to/php:/usr/share/pear:/usr/share/php"
カテゴリー: php タグ: ,

PHPでクライアントベースのOAuth認証

まさに誰得。
ブラウザベースは情報いっぱいあったんだけど、クライアントベースが見つからなかったので。
取得したaccess_token、access_token_secretを利用の仕方は下記で。
PEAR::HTTP_OAuthでxAuth – ぱんぴーまっしぐら

#!/usr/bin/env php
<?php
require_once 'HTTP/OAuth/Consumer.php';

define('CONSUMER_KEY',    'xxxxxxxxxxxxxxxxxxxx');
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

try {

  $http_request = new HTTP_Request2();
  $http_request->setConfig('ssl_verify_peer', false);

  $consumer_request = new HTTP_OAuth_Consumer_Request();
  $consumer_request->accept($http_request);

  $consumer = new HTTP_OAuth_Consumer(CONSUMER_KEY, CONSUMER_SECRET);
  $consumer->accept($consumer_request);

  $consumer->getRequestToken('http://twitter.com/oauth/request_token');
  $url = $consumer->getAuthorizeUrl('http://twitter.com/oauth/authorize');

  if (!$stdin = fopen('php://stdin', 'r')) {
    throw new Exception('stdin open failed');
  }

  echo 'Visit the following URL in your browser to authenticate twitter: ';
  echo $url."\n";
  echo 'Enter Twitter OAuth PIN: ';
  $pin = trim(fgets($stdin, 64));
  $consumer->getAccessToken('http://twitter.com/oauth/access_token', $pin);

  echo 'access_token: '.$consumer->getToken()."\n";
  echo 'access_token_secret: '.$consumer->getTokenSecret()."\n";

} catch (Exception $e) {

  echo $e->getMessage().' in '.$e->getFile().' line '.$e->getLine()."\n";
  exit(1);

}
カテゴリー: php タグ: , ,

ChromeのRSS Subscription Extension

RSS Subscription Extension(by Google) – Google Chrome 拡張機能ギャラリー
FirefoxのようにChromeでも簡単にRSSを登録できるようになる拡張機能

オプションからlivedoor Readerを追加
説明:「livedoor Reader」
URL:「http://reader.livedoor.com/subscribe/%s」

カテゴリー: 日記 タグ: ,

logrotateをユーザー権限で実行する

logrotateは、ローテーションの設定をするconfファイルと、ローテーションの状態を保存するstatusファイルが必要になる。
標準ではroot権限で実行されているので、ユーザー権限でstatusファイルへのアクセス権限がなく、別途用意する必要がある。

/path/to/access_logを1日ごとにローテーション、履歴は7つまで保存する。
confファイルは/home/hoge/etc/logrotate.conf

/path/to/access_log {
    daily
    missingok
    rotate 7
}

statusファイルは/home/hoge/lib/logrotate.status

テスト

$ /usr/sbin/logrotate -d -s /home/hoge/lib/logrotate.status /home/hoge/etc/logrotate.conf

実行

$ /usr/sbin/logrotate -s /home/hoge/lib/logrotate.status /home/hoge/etc/logrotate.conf

cronへの追加

$ crontab -e
0 4 * * * /usr/sbin/logrotate -s /home/hoge/lib/logrotate.status /home/hoge/etc/logrotate.conf

via:logrotate

カテゴリー: linux タグ:

PEAR準拠の構文チェック

Manual :: コードの提供にあたっての要求事項

インストール

# yum --enablerepo=remi,epel install php-pear-PHP-CodeSniffer

使い方

$ phpcs hoge.php
カテゴリー: php タグ:

ツイート非公開時のTwitterAPIの挙動

ツイート非公開時のTwitterAPIの挙動が一部違う。

ツイート非公開時に、取得しようとした時、共通のエラーが返されるAPI一覧。
Retweet周りは触ったことがないので、知っている限り。

Twitter API Wiki / Twitter REST API Method: statuses user_timeline
Twitter API Wiki / Twitter REST API Method: statuses friends
Twitter API Wiki / Twitter REST API Method: statuses followers
Twitter API Wiki / Twitter REST API Method: favorites

返ってくるステータスコード

401

返ってくる文字列

Not authorized

statuses showだけ返る結果が違うので注意が必要。
Twitter API Wiki / Twitter REST API Method: statuses show

返ってくるステータスコード

403

返ってくる文字列

Sorry, you are not authorized to see this status.
カテゴリー: 日記 タグ:

CentOS5.5でRubyGemsを利用する

RPMForgeリポジトリにRubyGemsパッケージの主要なものはあるが、ないものはコマンドでいれることになるので、パッケージは利用しない。
CentOS5.5のrubyは1.8.5と古いため、バージョンにあったものを利用する。

RubyGems

yum install ruby-devel gcc gcc-c++
cd /usr/local/src
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.5.zip
unzip rubygems-1.3.5.zip
cd rubygems-1.3.5
ruby setup.rb config

Passenger

yum install httpd-devel
gem install passenger
passenger-install-apache2-module
vim /etc/httpd/conf.d/passenger.conf

Ruby on Rails

gem install -v=2.3.5 rails

mysql

yum install mysql-devel
gem install mysql -v 2.7 -- --with-mysql-config=/usr/bin/mysql_config

hpricot

gem install hpricot -v=0.7

mechanize

yum install libxml2-devel libxslt-devel
gem install mechanize

sqlite3-ruby

yum install sqlite sqlite-devel
gem install sqlite3-ruby -v=1.2.4
カテゴリー: ruby タグ: ,

Services_Twitter::sendOAuthRequest

Services_Twitter::sendOAuthRequestではHTTP_Request2_Exceptionをcatchしていますが、実際はHTTP_OAuth_Exceptionをcatchしなきゃいけない。

Services_Twitterはベーシック認証周りは大丈夫だと思いますが、OAuth周りはまともにテストされてないので、結構バグあります。

カテゴリー: php タグ: ,

あとで書くよ

services_twitterのprepareRequestメソッド

続きを読む…

カテゴリー: php タグ:

blogのデータが吹っ飛びました

blogのデータと、redmineのwikiと、リポジトリが死にました。
超泣きたい。

カテゴリー: 日記 タグ: