vagrant:PHP7:aws:s3:doesBucketExist/doesObjectExist で常に false になる
vagrant環境でテストしているときにawsのs3にあるファイルとバケットがあるかどうかを確認できる以下のメソッドを使ってみたが、何故かfalseしか帰って来ない。
$result = $s3->doesBucketExist($bucket); $result = $s3->doesObjectExist($bucket], $path);
getObject()は動いていたので
$auth = [ 'key' => getenv('AWS_ACCESS_KEY_ID') , 'secret' => getenv('AWS_SECR ET_ACCESS_KEY'), "region" => "ap-northeast-1", 'version' => 'latest', ]; $s3 = S3Client::factory($auth); $s3_result = $s3->getObject( [ 'Bucket' => $bucket, 'Key' => $path, ]);
とか、書いて試してみたら
Error executing "GetObject" on "https://s3.ap-northeast-1.amazonaws.com/バケット名/キー"; AWS HTTP error: cURL error 6: Could not resolve host: s3.ap-northeast-1.amazonaws.com; Unknown error (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
というエラーがでて、そんなわけ無いだろ…と思って確認しようとしたら、vagrant上のapacheは普通に生きてて、ブラウザで動作確認はできるのに、vagrant自体が半分死んでてssh接続できなくなってたので再起動したら、普通に使えるよになった。無駄にはまったので、メモを残しておく。
MacOSX + PHP7.2 + PHPStorm +Xdebug をセットアップする
brewで一発でやりたかったけどまだ対応してないぽかったので。
をみるとPHP7.2に対応してるのは2.6.0以降。
HomebrewよりPECL推奨みたいで
# pecl install xdebug
で最新のものがインストールされる。2.6.0だった。 PHP.iniには自動的に追加されて、phpinfo() で確認するとインストール済なのが確認できる。
後はphp.iniかxdebug.iniにでも以下のような設定を入れてやればOK
[xdebug] zend_extension="xdebug.so" xdebug.remote_enable=1 xdebug.remote_port="9000" xdebug.profiler_enable=1 xdebug.profiler_output_dir="/tmp" xdebug.max_nesting_level=1000 xdebug.idekey = "PHPSTORM"
残りの設定はどこかでググってください
composer updateでエラーが出たけど解決したので貼っとく
検索したけど、結局PHPのバージョンが古くなってるだけだった。 5.x系だとダメで7.x系なら動いたので入れた…というか入ってたはずなのに消えてた…orz
検索しづらかったので、ログ貼って検索しやすくしとく
$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files
Incenteev\ParameterHandler\ScriptHandler::buildParameters Updating the "app/config/parameters.yml" file Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
In Configuration.php line 69:
Warning: date_default_timezone_get(): It is not safe to rely on the system'
s timezone settings. You are required to use the date.timezone setting or
the date_default_timezone_set() function. In case you used any of those me
thods and you are still getting this warning, you most likely misspelled th
e timezone identifier. We selected the timezone 'UTC' for now, but please s
et date.timezone to select your timezone.
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an
[RuntimeException]
error when the "'cache:clear --no-warmup'" command:
In Configuration.php line 69:
Warning: date_default_timezone_get(): It is not safe to rely on the system's
timezone settings. You are required to use the date.timezone setting or
the date_default_timezone_set() function. In case you used any of those methods
and you are still getting this warning, you most likely misspelled the
timezone identifier. We selected the timezone 'UTC' for now, but please
set date.timezone to select your timezone.
PHP:Symfony3:Doctrine:createNativeQuery:in句 の利用についてざっくり
ORMなんて嫌いだー。
とりあえず、複雑なSQLと仮定して、ナマでSQLを叩きたくなったら以下のような感じでいける。 ここらへん資料少くて辛い。誰かの役に立てば幸い。
$entityManager = $this->getDoctrine()->getManager(); $idlist= array(); for($i=0;$i<count($hogeList);$i++){ $idList[] = $hogeList[$i]; // in句で渡したい配列を入れる } $sql = "select hoge1,hoge2 from foo_table where var_clm in (:idList);"; $rsm = new ResultSetMapping(); $rsm->addScalarResult('hoge1', 'hogehoge'); // 結果セットのカラムのマッピング必須 $rsm->addScalarResult('hoge2', 'hogehage'); // 結果セットのカラムのマッピング必須(無いとselectに書いてても取得されない) $query = $entityManager->createNativeQuery($sql,$rsm) $query->setParameter("idList", $idList, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY); //配列を引数に渡す $data = $query->getResult();
PHPStormでソースコードが消える問題について
PHPStormでローカル編集したものを、PHPStormのDeploy機能でvagrantにファイルを送ってる or vagrantのsyncで送ってる。
だいたいは問題ないのだけど、たまに問題があって、何故かソースが消える。 編集画面ひらいたままだと、編集画面のソースが消える。ファイル自体は0バイトで残っている。
いろいろ調べたりぐぐってみたけど、同様の現象の人もいないようで結構困ってる…。 ということで、誰か同様の現象がでてここにたどり着いた人は、コメントに「俺も!」とかだけでもいいので書いておいてくれるとありがたい…。
追記:解決した
VagrantFileの中でconfig.vm.synced_folderを設定していると、フォルダが同期してコピーされてる…ではなくmountされてる状態になっているので、PHPStormからdeploy機能でファイル転送しようとすると、同じフォルダから同じフォルダに書き込む状態になるので、そこで一旦ファイルがゼロになってしまうぽい。
わかってから調べるとちゃんとした資料にもいきやすいな…。 syncedとか言ってるからrsync的なものだと思ってた…orz
PHPStormでPush failed: Failed with error: Could not read from remote repository.
Pushすると
Push failed: Failed with error: Could not read from remote repository.
とか言われる。
settings-->Version Control-->Git の SSH executable で Native を選択する。選択済みなら一度別のを選んで適用してから、もう一度選んで適用。
それでもダメなら
VCS -> Git -> Remotes.
で、URLを設定しなおしたら治った。
PHP:S3で取得したデータをImageMagickで処理する
取得した時にBodyに入ってるデータがblob形式なので、それにあわせて処理する。
$s3 = S3Client::factory($auth); $s3_result = $s3->getObject([ 'Bucket' => $bucket, 'Key' => $key, ]); $image = new \Imagick(); //Now I can read a binary file $image->readImageBlob($s3_result['Body']); $image->adaptiveResizeImage(150, 150, true);