herokuで実行されない時

app logsを見ます。
[vagrant@localhost heroku]$ heroku logs -t
2019-08-17T06:29:07.714312+00:00 app[web.1]: [17-Aug-2019 06:29:07 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mb_convert_encoding() in /app/backlog.php:23

ん? 
mb_convert_encoding()?

とりあえずcomposer.jsonをupdateして、herokuにpush

{
	"require" : {
		"ext-mbstring": "*",
		"google/apiclient": "^2.0"
	}
}

きたーーーーーーーーーーー 結局、GCP→Heroku→Google Spread sheetもOKでした。

Herokuの料金体系とは

さて、Herokuの料金体系はどうなっているのでしょうか?
Herokuというと、何となく「無料」のサーバーという概念が強かったのですが、Heroku Schedulerを使用しようとしたところ、クレジットカードの登録を要求されて、無料版と有料版があるということを理解。

Herokuの運営がSalesforceなので、やや不安が残るというか、変な課金のされ方をしないか心配ではある。

では早速見ていこう。以下のように○○ free dyno hours(○%) used this monthとあり、AWSのように容量課金ではなく、時間単位の課金のようだ。

ちなみに、このfree dynoは月550時間使えることが見て取れる。

そしてこのfree dynoはクレジットカードを登録すると、月1000時間使えるようになる。約2倍。何んかだいぶいい加減だな。

では早速クレジットカードを登録してみましょう。
登録後は、以下のように、free dyno houresが1000に増えていることがわかります。

で、Heroku Scheduler は Web Dynoとは別のOne-Off Dynoという仮想環境で実行される。で、One-Off Dynoで使用された時間はfree dyno houresから引かれる。つまり、cronだけで使うなら、約1/2時間になるイメージだろう。

続いて、Heroku Schedulerを登録していこう。

Heroku scheduler

[vagrant@localhost heroku]$ heroku addons:create scheduler:standard
Creating scheduler:standard on ⬢ peaceful-garden-15590… !
▸ Please verify your account to install this add-on plan (please enter a credit card) For more information, see
▸ https://devcenter.heroku.com/categories/billing Verify now at https://heroku.com/verify
[vagrant@localhost heroku]$ heroku addons:open scheduler
▸ Couldn’t find that add on.

あれ、何で?
コンソールにログインして見ましょう。

Heroku schedulerって金かかるの?

Herokuにdeploy

[vagrant@localhost local]$ mkdir heroku
[vagrant@localhost local]$ cd heroku
[vagrant@localhost heroku]$ ls
[vagrant@localhost heroku]$ touch index.php
[vagrant@localhost heroku]$ touch composer.json
[vagrant@localhost heroku]$ ls
composer.json index.php
[vagrant@localhost heroku]$ git init
Initialized empty Git repository in /home/vagrant/local/heroku/.git/
[vagrant@localhost heroku]$ git add .
[vagrant@localhost heroku]$ git commit -m “Hello heroku commit”
[master (root-commit) 683c29e] Hello heroku commit
Committer: vagrant
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

git config –global user.name “Your Name”
git config –global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

git commit –amend –author=’Your Name

1 files changed, 3 insertions(+), 0 deletions(-)
create mode 100644 composer.json
create mode 100644 index.php
[vagrant@localhost heroku]$ heroku create
Creating app… done, ⬢ peaceful-garden-15590
https://peaceful-garden-15590.herokuapp.com/ | https://git.heroku.com/peaceful-garden-15590.git
[vagrant@localhost heroku]$ git push heroku master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 295 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: Compressing source files… done.
remote: Building source:
remote:
remote: —–> PHP app detected
remote:
remote: NOTICE: Your ‘composer.json’ is completely empty!
remote:
remote: A completely empty file is not a valid JSON document.
remote:
remote: Heroku automatically corrected this problem, but it is strongly
remote: recommended you change the contents to at least ‘{}’.
remote:
remote: For documentation on Composer and dependency management, check
remote: out the introduction at https://getcomposer.org/doc/00-intro.md
remote:
remote: —–> Bootstrapping…
remote: —–> Installing platform packages…
remote: NOTICE: No runtime required in composer.lock; using PHP ^7.0.0
remote: – php (7.3.8)
remote: – apache (2.4.39)
remote: – nginx (1.16.0)
remote: —–> Installing dependencies…
remote: Composer version 1.9.0 2019-08-02 20:55:32
remote: —–> Preparing runtime environment…
remote: NOTICE: No Procfile, using ‘web: heroku-php-apache2’.
remote: —–> Checking for additional extensions to install…
remote: —–> Discovering process types
remote: Procfile declares types -> web
remote:
remote: —–> Compressing…
remote: Done: 15.7M
remote: —–> Launching…
remote: Released v3
remote: https://peaceful-garden-15590.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy… done.
To https://git.heroku.com/peaceful-garden-15590.git
* [new branch] master -> master

ほう、rubyじゃなくてもいけるやんか。
で、Herokuでcronってどうやるんだ?

あれ、Heroku Schedulerで行けそう?? もしかして^^

ターミナルベースでherokuにログイン

[vagrant@localhost ~]$ heroku –version
heroku/7.27.1 linux-x64 node-v11.14.0
[vagrant@localhost ~]$ heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/browser/54d1a025-4f83-4774-93e8-afe0faba719a
› Warning: Cannot open browser.
heroku: Waiting for login… ⣯
^C
[vagrant@localhost ~]$ heroku login –interactive
heroku: Enter your login credentials
Email:

Herokuを使おう

やっと戻って来ました

toolbeltはCLIのようですね。
https://devcenter.heroku.com/articles/heroku-cli

[vagrant@localhost ~]$ curl https://cli-assets.heroku.com/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
105 1892 105 1892 0 0 2942 0 –:–:– –:–:– –:–:– 19306
This script requires superuser access.
You will be prompted for your password by sudo.
Your path is missing /usr/local/bin, you need to add this to use this installer.
[vagrant@localhost ~]$ sudo curl https://cli-assets.heroku.com/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
105 1892 105 1892 0 0 5341 0 –:–:– –:–:– –:–:– 25567
This script requires superuser access.
You will be prompted for your password by sudo.
Your path is missing /usr/local/bin, you need to add this to use this installer.
[vagrant@localhost ~]$ wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz
–2019-08-09 00:02:07– https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz
cli-assets.heroku.com をDNSに問いあわせています… 13.32.54.88, 13.32.54.49, 13.32.54.116, …
cli-assets.heroku.com|13.32.54.88|:443 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 301 Moved Permanently
場所: https://cli-assets.heroku.com/heroku-linux-x64.tar.gz [続く]
–2019-08-09 00:02:08– https://cli-assets.heroku.com/heroku-linux-x64.tar.gz
cli-assets.heroku.com:443 への接続を再利用します。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 29106114 (28M) [application/gzip]
`heroku-linux-amd64.tar.gz’ に保存中

100%[==============================================================================>] 29,106,114 1.58M/s 時間 16s

2019-08-09 00:02:24 (1.76 MB/s) – `heroku-linux-amd64.tar.gz’ へ保存完了 [29106114/29106114]

[vagrant@localhost ~]$ ls
centos6 heroku-linux-amd64.tar.gz index.php zend

[vagrant@localhost ~]$ ls
centos6 heroku-linux-amd64.tar.gz index.php zend
[vagrant@localhost ~]$ tar xf heroku-linux-amd64.tar.gz
[vagrant@localhost ~]$ ls
centos6 heroku heroku-linux-amd64.tar.gz index.php zend
[vagrant@localhost ~]$ sed -i -e “/^export PATH$/i PATH=\$HOME/heroku/bin:\$PATH” ~/.bash_profile
[vagrant@localhost ~]$ export PATH=$HOME/heroku-client/bin:$PATH
[vagrant@localhost ~]$ heroku –version
bash: heroku: コマンドが見つかりません
[vagrant@localhost ~]$ export PATH=$HOME/heroku/bin:$PATH
[vagrant@localhost ~]$ heroku –version
heroku/7.27.1 linux-x64 node-v11.14.0

おいおいおい

[vagrant@localhost .ssh]$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
The key fingerprint is:
65:0a:17:62:84:01:83:3e:c4:44:43:b5:e1:d0:63:0a vagrant@localhost.localdomain
The key’s randomart image is:
+–[ RSA 4096]—-+
|=B=+.++ . |
|Eo+=+. . . |
|+ oo. . . o |
| + o + |
| . S |
| |
| |
| |
| |
+—————–+
[vagrant@localhost .ssh]$ ls
authorized_keys id_rsa id_rsa.pub
なんか眠くなって来た。

Heroku account

get start Heroku account
Heroku

Heroku CLI
https://devcenter.heroku.com/articles/heroku-cli

To verify your CLI installation use the heroku –version command.

heroku-cli/5.6.12-1708b34 (windows-386) go1.7.4

heroku create

> heroku create
Creating app... done, radiant-dawn-72472
https://radiant-dawn-72472.herokuapp.com/ | https://git.heroku.com/radiant-dawn-72472.git

To ensure you have properly created this remote, run the git remote -v command, you should see something output that reveals the two remotes listed, origin and heroku.

> git remote -v
heroku  https://git.heroku.com/radiant-dawn-72472.git (fetch)
heroku  https://git.heroku.com/radiant-dawn-72472.git (push)
origin  https://github.com/udacity/galeria.git (fetch)
origin  https://github.com/udacity/galeria.git (push)

Once you have your application deployed, Heroku will provide you with a URL you can visit to see your site. After this you can run heroku open. This will open up a browser window and navigate to the deployed application URL.

https://dashboard.heroku.com/apps

If you want to change the URL of your application in the future you can do this by logging into your Heroku Dashboard. Many other actions are also available on the dashboard.

Deployment pipeline
development->staging->production

Heroku will allow you one “dyno” or single command container for free. This means that on a free tier Heroku account, you can run one command on the container and you will not be charged for it.