さくら共有サーバー cake3.5インストール後の.htaccessの設定

www/cake/に testというappを作っています。
それぞれのhtaccessのRewriteBaseでカレントディレクトリを指定してあげます。

/cake/.htaccess

  
   RewriteEngine on  
   RewriteRule    ^$ test/webroot/    [L]  
   RewriteRule    (.*) app/webroot/$1 [L]  
   RewriteBase /  
  

/cake/test/.htaccess

  
    RewriteEngine on  
    RewriteRule    ^$    webroot/    [L]  
    RewriteRule    (.*) webroot/$1    [L]  
    RewriteBase /test
  

/cake/test/webroot/.htaccess


    RewriteEngine On
    RewriteBase /test/webroot
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

きたー

ここまでもってくるの、結構煩雑だな~
VPSの方が簡単にセットアップできるという謎現象ですね。

さくらサーバーでintlを入れた後にcakephp3.5エラー

intlも入ったし、さあ、確認とおもったら、

php composer.phar create-project --prefer-dist cakephp/app myapp

Problem 1
– cakephp/cakephp 3.5.9 requires ext-intl * -> the requested PHP extension intl is missing from your system.

これはがっかりしますね。
確かに、php -i | grep intlで何も表示されない。

原因は、この php.ini は/usr/local/php/5.6/lib/php.iniの方を読み込んでいるから。
コントロールパネルで設定したphp.iniの方は、

php -c /home/[username]/www/php.ini -i | grep intl 

で表示される。

というわけで、cake3.5を入れる際も、以下のように打ちます。

php -c /home/[username]/www/php.ini composer.phar create-project --prefer-dist cakephp/app test

こんどは上手くいってるようです。

さくら共有サーバーにintlを入れて、cakephp3.5をインストール

intlがないと動きません。
というこで、まずicuライブラリを入れます。ここはサクサクいきます。

$ cd ~/local/src
$ wget http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.tgz
$ tar zxvf icu4c-54_1-src.tgz
$ cd icu/source
$ ./configure --prefix=$HOME/local
$ gmake
$ gmake install

続いて、intl

$ cd ~/local/src
$ wget http://pecl.php.net/get/intl-3.0.0.tgz
$ tar zxvf intl-3.0.0.tgz
$ cd intl-3.0.0
$ phpize

次に、.configureをしますが、phpのバージョンを指定します。
/php/5.6/
ここでphpのバージョンを指定しないと、エラーになりました。

$ ./configure --prefix=$HOME/local --with-icu-dir=$HOME/local --with-php-config=/usr/local/php/5.6/bin/php-config
$ make

あとは、php.initでextensionのパスを通します。
phpinfo()に入ってることを確認。

バージョン指定のところ、毎回見落とすんだよな~
自暴自棄です。

centos php7.0.27にintlを入れようとして嵌ったこと

まず、intlを入れようとします。

# sudo yum install --enablerepo=remi --enablerepo=remi-php56 -y php-intl

すると、phpが7.0.27とエラー表示されます。

Error: Package: php-intl-5.6.34-1.el6.remi.x86_64 (remi-php56)
           Requires: php-common(x86-64) = 5.6.34-1.el6.remi
           Installed: php-common-7.0.27-1.el6.remi.x86_64 (@remi-php70)
               php-common(x86-64) = 7.0.27-1.el6.remi
           Available: php-common-5.3.3-49.el6.x86_

phpのバージョン確認

# php -v
PHP 7.0.27 (cli) (built: Jan  2 2018 12:12:41) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

intlのリストを表示

# yum list | grep intl
intltool.noarch                            0.41.0-1.1.el6              @anaconda       -CentOS-201703281317.x86_64/6.9
perl-libintl.x86_64                        1.20-1.el6                  base
php-intl.x86_64                            5.3.3-49.el6                base
php-symfony-intl.noarch                    2.3.42-1.el6                epel
php54-php-intl.x86_64                      5.4.45-14.el6.remi          remi-safe
php55-php-intl.x86_64                      5.5.38-8.el6.remi           remi-safe
php56-php-intl.x86_64                      5.6.34-1.el6.remi           remi-safe
php70-php-intl.x86_64                      7.0.28-1.el6.remi           remi-safe
php71-php-intl.x86_64                      7.1.15-1.el6.remi           remi-safe
php72-php-intl.x86_64                      7.2.3-1.el6.remi            remi-safe

php70-php-intl.x86_64 を入れます。

# sudo yum install php70-php-intl

はいったか確認します。

# php -i | grep intl
#

なに!? 入ってない。
/opt/remi/php70/root/usr/lib64/php/modules/ に入っている。

/usr/lib64/php/modules にintl.soを入れる。

phpinfo()

コマンドライン

# php -i | grep intl
intl
intl.default_locale => no value => no value
intl.error_level => 0 => 0
intl.use_exceptions => 0 => 0

ふー焦った。

optはアドオンアプリケーションソフトウェアパッケージ(追加アプリケーション)
remiサードパーティのリポジトリの一つ とのこと。

深部物性値(P波・S波)

P波・S波
http://www.j-shis.bosai.go.jp/api-dstruct-phys

$BASE_URL = "http://www.j-shis.bosai.go.jp/map/api/dstrct/V1/phys.json";
$obj = json_decode(file_get_contents($BASE_URL));

print_r("<pre>");
var_dump($obj);
print_r("</pre>");

P波
[“SVP”]=>
object(stdClass)#12 (33) {
[“tn31”]=>
string(4) “5500”
[“tn29”]=>
string(4) “5000”
[“tn20”]=>
string(4) “3400”
[“tn8”]=>
string(4) “2100”
[“tn5”]=>
string(4) “1800”
[“tn32”]=>
string(4) “5700”
[“tn7”]=>
string(4) “2000”
[“tn6”]=>
string(4) “2000”
[“tn11”]=>
string(4) “2300”
[“tn25”]=>
string(4) “4000”
[“tn13”]=>
string(4) “2400”
[“tn9”]=>
string(4) “2100”
[“tn4”]=>
string(4) “1800”
[“tn19”]=>
string(4) “3200”
[“tn17”]=>
string(4) “2700”
[“tn30”]=>
string(4) “5500”
[“tn3”]=>
string(4) “1700”
[“tn15”]=>
string(4) “2500”
[“tn33”]=>
string(4) “6000”
[“tn1”]=>
string(4) “1600”
[“tn18”]=>
string(4) “3000”
[“tn28”]=>
string(4) “4600”
[“tn27”]=>
string(4) “5000”
[“tn16”]=>
string(4) “2600”
[“tn10”]=>
string(4) “2200”
[“tn21”]=>
string(4) “3500”
[“tn22”]=>
string(4) “3600”
[“tn23”]=>
string(4) “3700”
[“tn24”]=>
string(4) “3800”
[“tn14”]=>
string(4) “2500”
[“tn26”]=>
string(4) “4000”
[“tn2”]=>
string(4) “1600”
[“tn12”]=>
string(4) “2400”
}

S波
[“SVS”]=>
object(stdClass)#9 (33) {
[“tn31”]=>
string(4) “3200”
[“tn29”]=>
string(4) “2700”
[“tn20”]=>
string(4) “1600”
[“tn8”]=>
string(3) “700”
[“tn5”]=>
string(3) “550”
[“tn32”]=>
string(4) “3300”
[“tn7”]=>
string(3) “650”
[“tn6”]=>
string(3) “600”
[“tn11”]=>
string(3) “850”
[“tn25”]=>
string(4) “2100”
[“tn13”]=>
string(3) “950”
[“tn9”]=>
string(3) “750”
[“tn4”]=>
string(3) “500”
[“tn19”]=>
string(4) “1500”
[“tn17”]=>
string(4) “1300”
[“tn30”]=>
string(4) “3100”
[“tn3”]=>
string(3) “450”
[“tn15”]=>
string(4) “1100”
[“tn33”]=>
string(4) “3400”
[“tn1”]=>
string(3) “350”
[“tn18”]=>
string(4) “1400”
[“tn28”]=>
string(4) “2900”
[“tn27”]=>
string(4) “2700”
[“tn16”]=>
string(4) “1200”
[“tn10”]=>
string(3) “800”
[“tn21”]=>
string(4) “1700”
[“tn22”]=>
string(4) “1800”
[“tn23”]=>
string(4) “1900”
[“tn24”]=>
string(4) “2000”
[“tn14”]=>
string(4) “1000”
[“tn26”]=>
string(4) “2100”
[“tn2”]=>
string(3) “400”
[“tn12”]=>
string(3) “900”
}

地震予想のため、首都圏のP-Wave, S-Waveのリアルタイム値を取得してグラフにしたいんだが、なんか違う気がする。
少し掘ろうとすると、専門性が一気に高くなってついていけん。

震度に応じて、google mapのアイコン表示を変える

DBから呼び出したmagnitudeの強弱に応じて、markerのiconをgetCircle関数で呼び込んで変えます。

var map;
var infoWindow = [];
var marker = [];

var place = JSON.parse('<?php echo $place_list; ?>');
var mag = JSON.parse('<?php echo $mag_list; ?>');
var lat = JSON.parse('<?php echo $lat_list; ?>');
var lng = JSON.parse('<?php echo $lng_list; ?>');

function initMap() {
    var mapLatLng = new google.maps.LatLng({lat: 35.681167, lng: 139.767052}); 
    map = new google.maps.Map(document.getElementById('map'), { 
     center: mapLatLng, 
      zoom: 2
   });

	 for (var i = 0; i < lat.length; i++) {
	        markerLatLng = new google.maps.LatLng({lat: lat&#91;i&#93;, lng: lng&#91;i&#93;});
	        marker&#91;i&#93; = new google.maps.Marker({ 
	         position: markerLatLng, 
	            map: map,
	            icon: getCircle(mag&#91;i&#93;)
	       });
	 
	     infoWindow&#91;i&#93; = new google.maps.InfoWindow({ 
	         content: '<div class="map">' + place[i] + ' マグニチュード:' + mag[i] + '</div>' 
	       });
	     
	     markerEvent(i);
	 }

	 function getCircle(magnitude) {
        return {
          path: google.maps.SymbolPath.CIRCLE,
          fillColor: 'red',
          fillOpacity: .2,
          scale: Math.pow(2, magnitude) / 2,
          strokeColor: 'white',
          strokeWeight: .5
        };
      }
	 
	function markerEvent(i) {
	    marker[i].addListener('click', function() {
	      infoWindow[i].open(map, marker[i]);
	  });
	}
 }

おお、改めてこれは感動した。

usgsの地震情報をphpで取得

タイムスタンプが何故か桁数が多いので、削除しています。項目は気象庁と合わせます。

$BASE_URL = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson";
$obj = json_decode(file_get_contents($BASE_URL));

echo "震央地名:" .$obj->features[65]->properties->place ."<br>";
$date = $obj->features[65]->properties->time;
$date = substr($date, 0, -3);
echo "地震の発生時間:" .date("Y/m/d H:i:s", $date) ."<br>";
echo "マグニチュード:" .$obj->features[65]->properties->mag ."<br>";
echo "緯度:" .$obj->features[65]->geometry->coordinates[1] ."<br>";
echo "経度:" .$obj->features[65]->geometry->coordinates[0] ."<br>";
echo "深さ:" .$obj->features[65]->geometry->coordinates[2] ."km<br>";

問題なさそうなので、最新200を配列に入れます。

$BASE_URL = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson";
$obj = json_decode(file_get_contents($BASE_URL));

for($i=0; $i<200; $i++){
	$place&#91;&#93; = $obj->features[$i]->properties->place;
	$date = $obj->features[$i]->properties->time;
	$date = substr($date, 0, -3);
	$time[] = date("Y/m/d H:i:s", $date);
	$mag[] = $obj->features[$i]->properties->mag;
	$lon[] =$obj->features[$i]->geometry->coordinates[1];
	$lat[] = $obj->features[$i]->geometry->coordinates[0];
	$depth = $obj->features[$i]->geometry->coordinates[2];
}

テーブルをつくります。

create table weather.quakes(
	id int unsigned auto_increment primary key,
	place varchar(255),
	time datetime unique,
	mag float,
	lat double(8,6),
	lng double(9,6),
	depth float
);

入りました。

index.ctpをつくってあげます。

<?php
	$this->assign('title', '地震速報');
?>
<?= $this->element('menu'); ?>
<h1>地震速報</h1>
<span style="color:gray">※United States Geological Surveyを元に10分毎に最新のデータに更新しています。</span><br><br>

	<?php 
	$i = 1;
	foreach ($quakes as $quake){
	echo "震央地名:" .h($quake->place)."<br>";
	echo "地震発生時間:" .($quake->time)."<br>";
	echo "マグニチュード:".($quake->mag)."<br>";
	echo "深さ:".($quake->depth)."km<br>";
	echo "緯度:". ($quake->lat)."<br>";
	echo "経度:".($quake->lng)."<br><br>";
	}
	?>

気象庁とUSGSの地震データを比較してみる

まず気象庁
———–
地震の発生日時 震央地名 緯度 経度 深さ M 最大震度
1 2018/03/12 19:21:26.0 沖縄本島近海 27°15.0′N 128°25.6′E 48km M4.6 3

USGS
———-
Magnitude
uncertainty
4.9 mb
± 0.1
Location
uncertainty
27.131°N 128.447°E
± 7.0 km
Depth
uncertainty
52.5 km
± 7.1
Origin Time 2018-03-12 10:21:26.840 UTC
Number of Stations –
Number of Phases 48
Minimum Distance 37.0 km (0.33°)
Travel Time Residual 1.18 s
Azimuthal Gap 74°
FE Region RYUKYU ISLANDS, JAPAN (238)

時間はほぼ一緒ですが、マグニチュード、緯度経度、depth、全て値が微妙に異なります。

マグニチュード:地震が発するエネルギーの大きさを対数で表した指標値
地震のエネルギーを1000の平方根を底とした対数で表した数値で、マグニチュードが 1 増えると地震のエネルギーは約31.6倍になり、マグニチュードが 2 増えると地震のエネルギーは1000倍になる

マグニチュード測定方法:地震計
USGS:GPSや地震計を一定間隔で配備して、ネットワーク化、地下深くまでドリルで穴を開けて分析

気象庁とUSGSでは、どちらのデータが精度が高いのか疑問に思ったのですが、
下記資料をざっと流し読みすると、やってる事にあまり違いがないように感じます。
http://www.spaceref.co.jp/homepage/colum/images/US_earthquake_observation.pdf

ということで、今回は、USGSのデータを使って、地震情報をつくっていきたいと思います。