<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="ja" xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <title type="text">STEP UP BLOG</title>
  <subtitle type="html">ステップアップしていくブログです。</subtitle>
  <link rel="self" type="application/atom+xml" href="http://capella.3rin.net/atom"/>
  <link rel="alternate" type="text/html" href="http://capella.3rin.net/"/>
  <updated>2014-09-22T09:27:37+09:00</updated>
  <author><name>たかはし</name></author>
  <generator uri="//www.ninja.co.jp/blog/" version="0.9">忍者ブログ</generator>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />
  <entry>
    <id>capella.3rin.net://entry/51</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/51/" />
    <published>2017-06-29T19:10:38+09:00</published> 
    <updated>2017-06-29T19:10:38+09:00</updated> 
    <category term="Laravel" label="Laravel" />
    <title>Laravelの開発環境でカスタムエラーページを表示させないために</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[Laravel 5.2対象。<br />
Laravel 5.2では、<br />
resources/views/errors<br />
以下に<br />
resources/views/errors/404.blade.php<br />
resources/views/errors/500.blade.php<br />
のようにHTTPステータスコードのビューファイルを置くことで、独自のエラーページを表示させることができます(ステータスコードでなくてもできますが)。<br />
しかし、開発環境では小綺麗なエラーページでなく、どんなエラーがどこで起きたか知りたいのが常。<br />
というわけで本番環境ではないときに、カスタムエラーページではなくLaravelのエラースタックトレース画面を表示させるにはどうすればいいか。<br />
Laravel 5.2でのエラーハンドリングは、<br />
app/Exceptions/Handler.php のHandlerクラスが取り扱っています。<br />
このクラスはExceptionHandlerクラスを継承していて、ExceptionHandlerクラスにはrenderHttpExceptionメソッドといういかにもそれっぽいメソッドがあります。<br />
このrenderHttpExceptionメソッドがカスタムエラーページを描画しています。<br />
そこでrenderHttpExceptionメソッドをHandlerクラスでオーバーライドしましょう。<br />

<pre class="&ldquo;brush:plain&rdquo;">/**
 * Render the given HttpException.
 *
 * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
 * @return \Symfony\Component\HttpFoundation\Response
 */
protected function renderHttpException(HttpException $e)
{
    if (!App::environment('production')) {
        return $this-&gt;convertExceptionToResponse($e);
    }

    return parent::renderHttpException($e);
}</pre>
<br />
上記をHandler.php内に記述すれば、本番環境以外でカスタムエラーページが表示されなくなります。<br />
という感じで快適なLaravelライフを(^人^)]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/50</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/50/" />
    <published>2017-05-31T18:58:42+09:00</published> 
    <updated>2017-05-31T18:58:42+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>サーバが増えるとつらい</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[最近行なった七面倒な作業にサーバ10台以上にSSL証明書をインストールするというものがありました。<br />
めんどー！泣<br />
sshログインして証明書を更新してApacheを再起動して、と1台目のサーバで作業した時点でこれは大変だと気付いたので、インストール用のシェルプログラムを書いて出来る限り自動化したのですが、それでもそこそこの時間がかかりました。<br />
サーバ毎に確認も必要で、なんですべてのサーバに証明書を置かないといけないのかと。。。<br />
こういう複数サーバ構成だと、やはりロードバランサーにSSL証明書を起きたいものです。<br />
即ちELB。(E)えげつないほど(L)楽ちんで(B)便利なロードバランサーことELB。<br />
ELB使うと楽ですよね。<br />
AWSにロックインされてしまいますが。<br />
操作もシンプルですし、唯一リダイレクトループにさえ気をつければこれほど便利なサービスはないと思います。<br />
ELBを使えばSSL証明書もELBに置きさえすればいいのでサーバ毎のインストールは必要ありません。<br />
というわけで、これから規模の大きいサーバ構成にしたいときはAWSをメインに検討していきたいですね。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/49</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/49/" />
    <published>2017-04-27T17:55:05+09:00</published> 
    <updated>2017-04-27T17:55:05+09:00</updated> 
    <category term="CentOS" label="CentOS" />
    <title>CentOS6以前とCentOS7でのよく使うコマンドのメモ</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[主にWebサーバを動かすときによく使うコマンドを挙げています。<br />
<br />
・サービス一覧<br />
CentOS6以前<br />

<pre class="brush:plain">$ chkconfig --list</pre>
<br />
CentOS7<br />

<pre class="brush:plain">$ systemctl list-units --type=service</pre>
<br />
<br />
・サービスの状態、起動、停止、再起動(例:httpd)<br />
CentOS6以前<br />

<pre class="brush:plain"># service httpd status
# service httpd start
# service httpd stop
# service httpd restart</pre>
<br />
CentOS7<br />

<pre class="brush:plain"># systemctl status httpd.service
# systemctl start httpd.service
# systemctl stop httpd.service
# systemctl restart httpd.service</pre>
<br />
<br />
・ファイアウォール<br />
CentOS6以前<br />

<pre class="brush:plain"># iptables -nvL
# iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT</pre>
<br />
CentOS7<br />

<pre class="brush:plain"># firewall-cmd --list-services --zone=public --permanent
# firewall-cmd --add-service=https --zone=public --permanent</pre>
<br />
firewalldはサービス名で追加削除できるのでわかりやすいですね。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/48</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/48/" />
    <published>2017-03-31T15:47:24+09:00</published> 
    <updated>2017-03-31T15:47:24+09:00</updated> 
    <category term="html" label="html" />
    <title>Font Awesome</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[仕事でFont Awesomeを使ってます。<br />
Font AwesomeはフリーのWebアイコンフォントです。<br />
商用利用可能です。<br />
<a href="http://fontawesome.io/" title="" target="_blank">http://fontawesome.io/</a><br />
味気ない業務サイトも見出しやメニューなどにアイコンが付くと、とたんにフレンドリーに見えてきます。<br />
使い方も簡単です。<br />
<a href="http://fontawesome.io/examples/" title="" target="_blank">http://fontawesome.io/examples/</a><br />
アイコンの種類も豊富で日々増えています。<br />
だいたい欲しいアイコンは揃っています。<br />
<a href="http://fontawesome.io/icons/" title="" target="_blank">http://fontawesome.io/icons/</a><br />
バッテリーアイコンなど残量に応じて11種類のアイコンが用意されています。<br />
これさえあれば他に何も要らないレベルです。<br />
もうアイコンだけで会話ができるレベルです。<br />
サイトにもう一味わかりやすさを求めているときに活用してみてはどうでしょうか。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/47</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/47/" />
    <published>2017-02-28T18:20:52+09:00</published> 
    <updated>2017-02-28T18:20:52+09:00</updated> 
    <category term="MySQL" label="MySQL" />
    <title>MySQLのSQLプロファイリング</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[MySQLの実行が遅いときはチューニングが必要です。<br />
MySQLのSQLチューニングですが、基本中の基本がexplainです。<br />
スロークエリログで見つけた遅いSQLをexplainで実行して、適切なインデックスが使用されているか調べるのが、まずはチューニングの第一歩です。<br />
それでも高速化したいSQLのどこが遅いのかわからないときはSQLのプロファイリング情報を調べます。<br />
プロファイリングは以下のようにして表示できます。<br />

<pre class="brush:plain">mysql&gt; SET PROFILING = 1;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; SELECT ...
...
...
117 rows in set (6 min 54.15 sec)

mysql&gt; SHOW PROFILE;
+------------------------------+------------+
| Status                       | Duration   |
+------------------------------+------------+
| starting                     |   0.000246 |
| checking permissions         |   0.000004 |
| checking permissions         |   0.000003 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000002 |
| checking permissions         |   0.000005 |
| Opening tables               |   0.000030 |
| System lock                  |   0.000005 |
| Table lock                   |   0.000094 |
| optimizing                   |   0.000032 |
| statistics                   |   0.000051 |
| preparing                    |   0.000033 |
| Creating tmp table           |   0.000026 |
| executing                    |   0.000003 |
| Copying to tmp table         |   0.161709 |
| Sorting result               |   0.000767 |
| Sending data                 |   0.002630 |
| removing tmp table           |   0.000008 |
| Sending data                 |   0.000007 |
| init                         |   0.000112 |
| optimizing                   |   0.000022 |
| statistics                   |   0.000041 |
| preparing                    |   0.000030 |
| Creating tmp table           |   0.000066 |
| executing                    |   0.000003 |
| Copying to tmp table         |   0.050874 |
| converting HEAP to MyISAM    |   0.033028 |
| Copying to tmp table on disk | 103.846074 |
| Sorting result               | 158.297312 |
| Sending data                 | 151.018799 |
| end                          |   0.000026 |
| removing tmp table           |   0.807298 |
| end                          |   0.000016 |
| query end                    |   0.000004 |
| freeing items                |   0.000045 |
| removing tmp table           |   0.000009 |
| freeing items                |   0.000010 |
| removing tmp table           |   0.000004 |
| freeing items                |   0.000005 |
| removing tmp table           |   0.000006 |
| freeing items                |   0.000033 |
| removing tmp table           |   0.000007 |
| closing tables               |   0.000011 |
| logging slow query           |   0.000002 |
| logging slow query           |   0.000006 |
| cleaning up                  |   0.000007 |
+------------------------------+------------+
50 rows in set (0.00 sec)</pre>
<br />
上記のように調べたいSQLを実行した後にSHOW PROFILEします。<br />
これはJOINの多いSQLを実行したときですが、めちゃくちゃtmpテーブルを作ってますね。。。<br />
この場合はそもそもJOINがここまで必要とするテーブル構成でいいのか疑問となってきます。<br />
また、"Sorting result"に時間がかかっているのでORDER BYかもしくはGROUP BYがボトルネックとなっていると思われます。<br />
これ以外に手軽にできるチューニングというと、あとはバッファサイズの変更でしょうか。これはサーバスペックなどとにらめっこしながら適正値を探っていかないとなりません。<br />
という感じで、今回はMySQLのSQLプロファイリング情報を調べてボトルネックを突き止めるということをまとめてみました。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/46</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/46/" />
    <published>2017-01-30T19:18:01+09:00</published> 
    <updated>2017-01-30T19:18:01+09:00</updated> 
    <category term="php" label="php" />
    <title>既存PHPに後から拡張モジュールをインストールする</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[既にインストールされているPHPに後から拡張モジュールを追加しないといけない場合があると思います。<br />
そのようなときの拡張モジュールのインストール手順です。<br />
今回は例としてzipモジュールをインストールします。<br />
PHPを新しくインストールするときならば--enable-zipをconfigureオプションとして指定すればいいのですが、この場合既にPHPはインストールされているのでそうもいきません。<br />
尚、PHPをソースコードからコンパイル、インストールした場合で、HTTPサーバはApacheです。<br />

<pre class="brush:plain">$ cd /usr/local/src/php-5.x.xx/ext/zip</pre>
<br />
PHPソースコードのディレクトリにはextという拡張モジュールのソースコードが入っているディレクトリがあるので、extの中の該当するモジュールのディレクトリに移動します。<br />

<pre class="brush:plain">$ sudo /usr/local/bin/phpize
$ sudo ./configure --with-php-config=/usr/local/bin/php-config
$ sudo make
$ sudo make test
$ sudo make install
$ sudo vi /usr/local/lib/php.ini
+ extension=zip.so
$ sudo service httpd restart
$ php -i | grep zip
Registered PHP Streams =&gt; compress.zlib, php, file, glob, data, http, ftp, zip, phar  
gzip compression =&gt; enabled
bzip2 compression =&gt; disabled (install pecl/bz2)
zip
Libzip version =&gt; 0.10.1</pre>
<br />
以上となります。<br />
configureでphp-configのエラーが出る場合は--with-php-configでphp-configのパスを指定してあげます。<br />
簡単ですね。<br />
という感じで気軽にモジュールは追加していったらいいと思います(外す場合はphp.iniのextension記述を削除すればいいので)。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/45</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/45/" />
    <published>2016-12-30T16:13:02+09:00</published> 
    <updated>2016-12-30T16:13:02+09:00</updated> 
    <category term="php" label="php" />
    <title>PsySHでPHPのREPL</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[RubyやPythonなどと同様にPHPにもREPLがあります。<br />
それがPshSHです。<br />
REPLとは"Read Eval Print Loop"の略で対話型の実行環境を指します。<br />
<br />
<a href="http://psysh.org/" title="" target="_blank">http://psysh.org/</a><br />
<br />
ありがたいことに最新のLaravel5.3では自動でインストールされます。<br />
入ってなくてもcomposerを使えば簡単にインストールできます。<br />

<pre class="brush:plain">$ composer require psy/psysh:@stable</pre>
<br />
まずは起動してみます。<br />

<pre class="brush:plain">$ ./vendor/psy/psysh/bin/psysh 
Psy Shell v0.8.0 (PHP 7.1.0 &mdash; cli) by Justin Hileman
&gt;&gt;&gt; help
  help       Show a list of commands. Type `help [foo]` for information about [foo].      Aliases: ?                     
  ls         List local, instance or class variables, methods and constants.              Aliases: list, dir             
  dump       Dump an object or primitive.                                                                                
  doc        Read the documentation for an object, class, constant, method or property.   Aliases: rtfm, man             
  show       Show the code for an object, class, constant, method or property.                                           
  wtf        Show the backtrace of the most recent exception.                             Aliases: last-exception, wtf?  
  whereami   Show where you are in the code.                                                                             
  throw-up   Throw an exception out of the Psy Shell.                                                                    
  trace      Show the current call stack.                                                                                
  buffer     Show (or clear) the contents of the code input buffer.                       Aliases: buf                   
  clear      Clear the Psy Shell screen.                                                                                 
  history    Show the Psy Shell history.                                                  Aliases: hist                  
  exit       End the current session and return to caller.                                Aliases: quit, q               
&gt;&gt;&gt; </pre>
<br />

<pre class="brush:plain">&gt;&gt; $arr = [1,2,3];
=&gt; [
     1,
     2,
     3,
   ]
&gt;&gt;&gt; 1 + 2;
=&gt; 3
&gt;&gt;&gt; function square($x) {
... return $x*$x*$x;
... }
=&gt; null
&gt;&gt;&gt; square(4);
=&gt; 64</pre>
<br />
というようにインタラクティブにPHPを実行できます。<br />
試してみてはいかがでしょうか。<br />
それではよいお年を。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/44</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/44/" />
    <published>2016-11-30T17:53:54+09:00</published> 
    <updated>2016-11-30T17:53:54+09:00</updated> 
    <category term="php" label="php" />
    <title>privateの罠</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[最近ハマった挙動について書きます。<br />
コードを見たほうが早いので以下にコード。<br />

<pre class="brush:plain">&lt;?php

class ClassA
{
    private $member_variable = 'A';

    public function getMemberVariable()
    {
        return $this-&gt;member_variable;
    }
}

class ClassB extends ClassA
{
    private $member_variable = 'B';

    public function getMemberVariable()
    {
        return $this-&gt;member_variable;
    }
}

class ClassC extends ClassA
{
    private $member_variable = 'C';
}

$a = new ClassA();
$b = new ClassB();
$c = new ClassC();

echo $a-&gt;getMemberVariable()."\n";
echo $b-&gt;getMemberVariable()."\n";
echo $c-&gt;getMemberVariable()."\n";</pre>
<br />

<pre class="brush:plain">$ php test.php 
A
B
A</pre>
<br />
$c-&gt;getMemberVariable()で"C"が返ってくると思ったら"A"でした。。<br />
"C"を返すには以下のようにprivateをprotectedに変えるとできます。<br />

<pre class="brush:plain">&lt;?php

class ClassA
{
    protected $member_variable = 'A';

    public function getMemberVariable()
    {
        return $this-&gt;member_variable;
    }
}

class ClassB extends ClassA
{
    protected $member_variable = 'B';

    public function getMemberVariable()
    {
        return $this-&gt;member_variable;
    }
}

class ClassC extends ClassA
{
    protected $member_variable = 'C';
}

$a = new ClassA();
$b = new ClassB();
$c = new ClassC();

echo $a-&gt;getMemberVariable()."\n";
echo $b-&gt;getMemberVariable()."\n";
echo $c-&gt;getMemberVariable()."\n";</pre>
<br />

<pre class="brush:plain">$ php test.php 
A
B
C</pre>
<br />
子クラスから親クラスのメソッドを呼んで、そのメソッド内でprivate変数を呼ぶと親のprivate変数になるんですね。<br />
理屈がわかればなるほどなんですが、どこがおかしいのか見つけるのが意外と難しかったです。。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/43</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/43/" />
    <published>2016-10-31T19:01:58+09:00</published> 
    <updated>2016-10-31T19:01:58+09:00</updated> 
    <category term="Linux" label="Linux" />
    <title>rsyncのスラッシュありなしの注意点</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[rsyncでたまに大きいディレクトリを同期し終わってから失敗したとならないための注意。<br />
同期元にスラッシュをつけるかつけないかの話です。<br />
以下、例です。<br />

<pre class="brush:plain">$ ls
.  ..  dst  src
$ ls src
.  ..  a.txt  b.txt  c.txt
$ ls dst
.  ..
</pre>
<br />
スラッシュあり<br />

<pre class="brush:plain">$ rsync -avh src/ dst
sending incremental file list
./
a.txt
b.txt
c.txt

sent 226 bytes  received 72 bytes  596.00 bytes/sec
total size is 6  speedup is 0.02
$ ls dst
.  ..  a.txt  b.txt  c.txt</pre>
<br />
スラッシュなし<br />

<pre class="brush:plain">$ rsync -avh src dst
sending incremental file list
src/
src/a.txt
src/b.txt
src/c.txt

sent 240 bytes  received 73 bytes  626.00 bytes/sec
total size is 6  speedup is 0.02
$ ls dst
.  ..  src
$ ls dst/src/
.  ..  a.txt  b.txt  c.txt</pre>
<br />
スラッシュがあると中のファイルだけを同期させますが、スラッシュがないとディレクトリごと同期させるようになります。<br />
目的によりますが、気をつけないと想定していないディレクトリ構成となって同期してしまうので注意しましょう。]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
  <entry>
    <id>capella.3rin.net://entry/42</id>
    <link rel="alternate" type="text/html" href="http://capella.3rin.net/Entry/42/" />
    <published>2016-09-30T18:55:27+09:00</published> 
    <updated>2016-09-30T18:55:27+09:00</updated> 
    <category term="html5" label="html5" />
    <title>html5のdownload属性</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[Webサイトから何かファイルをダウンロードさせたいとき、例えば、<br />

<pre class="brush:plain"><a href="sample.pdf">ダウンロードサンプル</a></pre>
<br />
のようにリンクを貼った場合、ファイルの種類によってはダウンロードではなくブラウザで表示するかたちになります(PDFなど)。<br />
気を利かせて開いてくれたのはうれしいけれど、今見たいわけじゃないんだブラウザ君。<br />
というわけでそんなときに便利なのがhtml5で仕様が作られたdownload属性です。<br />
<br />
<a href="https://developer.mozilla.org/ja/docs/Web/HTML/Element/a" title="" target="_blank">https://developer.mozilla.org/ja/docs/Web/HTML/Element/a</a><br />
<br />

<pre class="brush:plain"><a href="sample.pdf" download="">ダウンロードサンプル</a></pre>
<br />
のように書くと、リンク先が明示的にダウンロードされるようになります。しかも<br />

<pre class="brush:plain"><a href="sample.pdf" download="ダウンロードサンプル.pdf">ダウンロードサンプル</a></pre>
<br />
のように書くと、ダウンロードするときのファイル名までも指定できます。<br />
便利！！<br />
しかも！！<br />
一部のブラウザまたの名をSafariやIEではこの属性は使えません！！<br />
早く対応してください＞＜]]> 
    </content>
    <author>
            <name>たかはし</name>
        </author>
  </entry>
</feed>