【问题标题】:Why doesn't Heroku see a file I create after I deploy?为什么 Heroku 在部署后看不到我创建的文件?
【发布时间】:2015-06-06 19:18:00
【问题描述】:

我想像 Rails 一样在 Yii 中设置资产编译和压缩。 http://www.yiiframework.com/doc-2.0/guide-structure-assets.html

我正在考虑使用 PHP 缩小器。我宁愿不必手动编译资产并将其签入 Git。然而,即使它有效,Heroku 似乎也不会为不在 Git 中的新文件提供服务器。为什么?

>heroku run bash
Running `bash` attached to terminal... up, run.6857
~ $ cd web
cd web
~/web $ ls
ls
MySample.php  css          images          index.php  robots.txt
assets        favicon.ico  index-test.php  js
~/web $ echo hello > hello.txt
echo hello > hello.txt
~/web $ cat hello.txt
cat hello.txt
hello
~/web $ exit
exit
exit

$ curl -I http://xxxxxx.herokuapp.com/hello.txt
HTTP/1.1 404 Not Found

【问题讨论】:

  • 我已经知道 Heroku 使用临时文件系统。我不需要保存已编译的资产,因为它们可以在第一次请求时生成。

标签: php git heroku yii yii2


【解决方案1】:

找不到 hello.txt 的原因是因为您的 curl -I 请求将由您的应用程序的新实例处理。为了演示,我可以在 bash 中删除我的 index.php,但是当我使用 curl -I 检索它时,我得到 200 OK。

$ heroku run bash
Running `bash` attached to terminal... up, run.3070
~ $ cd web
~/web $ ls                    
index.php
~/web $ rm index.php      
~/web $ ls
~/web $ curl -I http://xxxxx.herokuapp.com/index.php
HTTP/1.1 200 OK

另一种显示方式是打开两个不同的 bash 连接,然后运行 ​​heroku ps

$ heroku ps
=== run: one-off processes
run.3070 (1X): up 2015/04/01 19:30:07 (~ 37m ago): `bash`
run.7783 (1X): up 2015/04/01 19:59:48 (~ 8m ago): `bash`

这两个进程不会共享临时内存。

【讨论】:

  • heroku run 创建了一个新实例...因此通过应用程序缩小资产并将其保存到临时文件系统仍然可以工作,因为它们保存在正在运行的实例上。跨度>
猜你喜欢
  • 1970-01-01
  • 2021-01-18
  • 2018-07-27
  • 2021-08-09
  • 1970-01-01
  • 2020-04-12
  • 2012-05-13
  • 1970-01-01
  • 2022-10-01
相关资源
最近更新 更多