Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: For Cloud Environment - Customizable temp file prefix naming #884

Closed
AndrewEQ opened this issue Nov 4, 2015 · 13 comments
Closed

Comments

@AndrewEQ
Copy link

AndrewEQ commented Nov 4, 2015

Hey guys,

I'm trying to get F3 working on Google App Engine (GAE), the problem is that the F3 app is served from multiple servers, on each server, a request for a template would be expecting a temp filename made up of a hash(ROOT . BASE). ROOT changes accordingly to the server serving the request, so the expected template name changes from server to server.

This wouldn't be a problem except that GAE is read-only(attempting to write to disk would throw an error), so a solution is to upload Temp files generated locally to GAE, the main issue then being that the temp filenames won't match up with the temp filenames requested per server.

Could you code it to allow the "template prefix" to be customisable?

base.php ... 
Preview->render ... 

$fw->get('ROOT')

to something like:

($fw->exists('TEMPLATE_ROOT') ? $fw->get('TEMPLATE_ROOT') : $fw->get('ROOT'))
@ikkez
Copy link
Collaborator

ikkez commented Nov 4, 2015

What's the suggested solution from GAE for apps that need to write things? I'm sure someone else already had the same problem.

@xfra35
Copy link
Collaborator

xfra35 commented Nov 4, 2015

Here it is: https://cloud.google.com/appengine/docs/php/googlestorage/

But since you're after executing raw PHP templates, View should be the most appropriate.

@ikkez
Copy link
Collaborator

ikkez commented Nov 4, 2015

Ah okay. So maybe just try to set $f3->set('TEMP', 'gs://temp/'); @AndrewEQ

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

Tried setting the TEMP @ikkez but GAE's wrapper doesn't work for directory functions(like mkdir - https://github.com/bcosca/fatfree/blob/master/lib/base.php#L2632) only file specific functions, so it threw an error.

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

I'm lovin F3's template language too much right now @xfra35 😄

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

Oh wait @ikkez I see its supported (https://cloud.google.com/appengine/docs/php/googlestorage/advanced#php_filesystem_functions_support_on_google_cloud_storage), so maybe its something to do with my bucket, lemme check...

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

So I get "file_put_contents(): Exclusive locks may only be set for regular files" (https://github.com/bcosca/fatfree/blob/master/lib/base.php#L1817)

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

...yeah, so when I remove the LOCK_EX|, it works! Need a more permanent solution though.

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

Ok, so that roughly resolves the file writing issue but in terms of templates written, the template has a prefix made up of the hash(ROOT**(which is $_SERVER['DOCUMENT_ROOT'])** . BASE . filename . 'php'), which would mean that every time a template is written, it will be based off the servers ROOT and if there are multiple servers serving a template, there will be multiple versions of the same template written.

I found the similar issue in terms of caching, so would also like to request an option to customize the name here too: https://github.com/bcosca/fatfree/blob/master/lib/base.php#L2409 as when a key is cached, it could also have multiple versions of itself written depending on the server serving the request.

@AndrewEQ
Copy link
Author

AndrewEQ commented Nov 5, 2015

Ok, so my updated findings/requests:

File writing on GAE issue - (https://github.com/bcosca/fatfree/blob/master/lib/base.php#L1817)

(($fw->exists('NO_LOCK_EX'))? 0 : LOCK_EX) 
  • replaced with a flag but not sure what the permanent solution is here.

Cloud template naming issue - https://github.com/bcosca/fatfree/blob/master/lib/base.php#L2639

($fw->exists('TEMPLATE_ROOT') ? $fw->get('TEMPLATE_ROOT') : $fw->get('ROOT'))
  • custom name for "template root"

Caching naming issue - https://github.com/bcosca/fatfree/blob/master/lib/base.php#L2409

($fw->exists('CACHE_ROOT') ? $fw->get('CACHE_ROOT') : $_SERVER['SERVER_NAME'])
  • custom name for "cache root"

@choff723
Copy link

choff723 commented May 4, 2016

Hi everyone, regarding TEMP, per https://gae-php-tips.appspot.com/2015/03/03/file-system-changes-in-app-engine-1-9-18/ we can now use the in-memory file system for this, so f3->set('TEMP', sys_get_temp_dir()).

Chris

ikkez added a commit to f3-factory/F3com-data that referenced this issue Nov 4, 2016
@ikkez
Copy link
Collaborator

ikkez commented Nov 4, 2016

The temp file name prefix can now be adjusted with the SEED var. f3-factory/fatfree-core#149
A hint about sys_get_temp_dir() for GAE was added to the docs.

@ikkez ikkez closed this as completed Nov 4, 2016
@AndrewEQ
Copy link
Author

AndrewEQ commented Dec 1, 2016

Hey @ikkez! The seed solves the taking advantage of the templates cache(TEMP) across multiple servers via setting it to the cloud storage BUT using sys_get_temp_dir() for TEMP doesn't store the files beyond the request: "The in memory filesystem will be flushed at the end of the request, and is not shared in between requests to the same instance."(https://gae-php-tips.appspot.com/2015/03/03/file-system-changes-in-app-engine-1-9-18/) This is great for actual temporary stuff but the template cache is tied to the TEMP dir ...so we won't be able to take advantage of the template cache(TEMP).

I've set our TEMP to a cloud storage dir, it writes and reads from the cloud storage dir :)

ikkez added a commit to f3-factory/F3com-data that referenced this issue Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants