Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've recently added some code to my Atari Gamer website to email me whenever an error is detected or an exception is thrown from my code. I was expecting to start receiving error detail emails but when they started coming in, I was surprised at the errors that I was seeing.

On the most part what I saw were errors with file_get_contents() whenever I was trying to serve what essentially equates to a '404 page'. The errors looked like this...
 Error
ERROR: file_get_contents(../retroarch/ag404.lnx): failed to open stream: No such file or directory


The code was trying to open a file from the application file system. The code causing the above error looked like this...
 Code
$content = file_get_contents('../retroarch/ag404.lnx');


Of course the file that the code was trying to open was present on the file system. This was tested on the dev server and worked as expected.

To be sure that the production behaviour was different I decided to have a look at the deployed source code for my app, and was surprised that the 'retroarch' directory that the code was expecting, was not shown in the source code browser. I guess I overlooked testing this on the production server once it eventually got deployed, so it's been running like that for months. Lesson learned - never trust the dev server.
gae_static1.png


This got me thinking that the problem was most likely with app.yaml. The entry that I had for the 'retroarch' directory looked like this...
 app.yaml
- url: /retroarch
static_dir: retroarch
secure: always
redirect_http_response_code: 301




Since I was using the static_dir directive, there was was a small detail that I overlooked. It was plain as day in the documentation however...
All files in this directory are uploaded with your app as static files. App Engine stores and serves static files separately from your app's files. Static files are not available in the app's file system by default. This can be changed by setting the application_readable option to true.


So in order to read the file programatically all I needed to do was set application_readable to true! Quite an obvious fix, but it does annoy me that the dev server does not have this behaviour. Anyway, I changed the handler to look like this...
 app.yaml
- url: /retroarch
static_dir: retroarch
application_readable: true
secure: always
redirect_http_response_code: 301


After deploying the app again, the source code listing included the directory and the file that the code was trying to open...
gae_static2.png


Problem solved!

It should be noted that the application_readable directive is deprecated in later versions of the AppEngine SDK. I've not looked at the migration guide to find out more details as I'm most likely going to be moving away from AppEngine before I'm forced to upgrade.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.