Yii2: Support for Google App Engine

Created on 9 Oct 2013  ·  43Comments  ·  Source: yiisoft/yii2

Google App Engine now supports PHP. We should check if Yii can run on it and may consider providing some extensions to support specific GAE features such as task queues.

docs

Most helpful comment

@iadj translated.

All 43 comments

I have approved developer account for it. GAE's difference is that it doesn't have any file system so nothing can be written to runtime. I think I can handle setting up a test application to verify it works.

Well it has a filesystem but it is read-only. You can use GAE's blobstore to save into persistent storage.

It would be great @samdark if you could come up with a solution for all such services that are deployed into various VMs dynamically in cloud/distributed environments. Perhaps runtime using a cache backend and the option to set up an nfs path to store?

Definetely if we are to support GAE, blobstore would have to be implemented in the framework.

Hmm.. Disregard the blobstore it seems it is currently not available for PHP on GAE. The only option offered by Google right now for PHP apps is GCS (Google Cloud Storage).
https://developers.google.com/appengine/docs/php/refdocs/
Google favors Python it seem.

Issue: $_SERVER['SCRIPT_NAME'] is not available. At least when running GAE app locally. Quickfix is adding

<?php
$_SERVER['SCRIPT_NAME'] = '/index.php';

to entry script.

Since app is often in subdir, need the following in index.php:

$_SERVER['SCRIPT_FILENAME'] = 'index.php';

app.yaml for basic app:

application: yii-demo
version: 1
runtime: php
api_version: 1

handlers:

- url: /(.*\.(gif|png|jpg|css|js))
  static_files: web/\1
  upload: web/(.*\.(gif|png|jpg))

- url: /.*
  script: web/index.php

Nothing is writable so there's no way to host assets in file system.

Here's the Yii 1.1 that is runnable on GAE: https://github.com/poul-kg/yii-app-engine

@samdark did you manage run the Web application in GAE? I mean, maybe you tested, and everything works except assets?

No, I haven't finished it.

I think google storage is ok for this solution.

I'm still having issues launching Yii2 on App Engine... are there any tutorials or a walk through that would elaborate on the process. I am relatively knew to all 3, Yii, App Engine and servers in general, so a real step by step or even a video would be awesome.

Maybe I'm just being a cheapskate.. Are you using a Compute Engine with this method? I thought I'd try installing a different PHP framework and I have Joomla running at fat-cow already, that I'll probably need to move to App Engine anyways. So in preparing to tackle the transition, I found Google's tutorial on installing it, but I noticed they are using the compute engine. https://cloud.google.com/compute/docs/tutorials/setup-joomla
Would that make it easier, if not a few cents more expensive? I think it's all the extra server software that is getting in my way of just finding a simple installation. It comes with a free trial, that would give me time to get through the Yii tutorials.

It's not as straightforward as just "installing". Environment is pretty different from common Linux, PHP, Apache, MySQL.

@samdark have you arrived at any conclusions in your test of Yii2 on GAE?
This seems to be very interesting considering the potentials but there doesn't seem to be any documentation of anyone's efforts in a way that tracks the issues and gives the Yii2 community an opportunity to resolve them. How can we put community effort behind this?

Nope. It was long time ago and I haven't finished it that time.

Is there any plan to add this feature in the near future?
Is it possibile to have a list of the bottlenecks to get a working deploy in order to try to dig a bit?

@masiorama, @samdark - It appears that the challenge from Google's point of view is to eliminate any dependency on unsupported PHP functions or in our case the use of such PHP functions by the YII framework (Disclaimer: I'm not an expert)

Here's a summary of unsupported PHP features according to Google: -

DISABLED FUNCTIONS

Either for security reasons, or for compatibility with Google App Engine execution environment, some PHP functions have been disabled. Some of these functions can be explicitly re-enabled in the php.ini file for your application.

Permanently disabled functions

The following functions have been permanently disabled in Google App Engine:
disk_free_space()
disk_total_space()
diskfreespace()
escapeshellarg() and escapeshellcmd()
exec()
highlight_file()
lchgrp(), lchown(), link(), and symlink()
passthru()
pclose() and popen()
proc_close(), prog_get_status(), proc_nice(), proc_open(), and proc_terminate()
set_time_limit()
shell_exec()
show_source()
system()

Google App Engine does not include the pcntl module, and thus the functions provided by pcntl are not available to PHP programs running in Google App Engine.

Partially restricted functions

The Google App Engine for PHP runtime does not support the /e pattern modifier of the preg_replace() andmb_ereg_replace() functions. See the PREG_REPLACE_EVAL documentation for the deprecation notice and an example of how to update your code to use preg_replace_callback() instead.

Disabled stream transports

The following stream transports have been disabled.
ssl
sslv2
sslv3
tcp
tls
udg
udp
unix

See details here https://cloud.google.com/appengine/docs/php/

I think it will be worth it to develop wrappers for any of these features that implements the required function without breaking compatibility with GAE platform. The ability to scale load at Google scale alone is worth it. (Google: Some of the world’s most popular web services are built on our platform. You can scale up to 7 billion requests per day and automatically scale down when traffic subsides. See details here https://cloud.google.com/appengine/)

For my part, I will contribute whatever is within my ability to support any community effort around this. I think what is required is someone to lead the effort with enough knowledge of exactly what needs to be done.

Regards,

Adam

i will try Google Cloud and test it )

as far as I see these functions should not cause any problems as they are (if at all) only used in very specific parts of the frameworks functionality.

Any news on this? Cloud seems to be the future.

Any solution for the obvious problems like asset publishing and runtime directory?

I think google offers custom logging API.

Haven't looked at it anymore but it seems there's assets component available:
https://github.com/postor/yii2-for-sae/blob/master/SaeAssetManager.php.

The rest are logs and cache for which non-file backends are already available.

Overall, I think GAE support could be released as application template.

I just tried it with the development server, and it seems to work, but the path is wrongly generated because of the way $_SERVER values are set in this environment.

Documentation: https://cloud.google.com/appengine/docs/php/config/appconfig#Updated_PHP_SELF

More precise, for this config:

application: myapp
version: alpha-001
runtime: php55
api_version: 1

handlers:
- url: /assets
  static_dir: web/assets

- url: /.*
  script: web/index.php

we get:

'REQUEST_URI' => string '/'
'PHP_SELF' => string '/web/index.php'
'PATH_INFO' => string '/'
'SCRIPT_FILENAME' => string '/usr/share/nginx/current/web/index.php'
'SCRIPT_NAME' => string '/web/index.php'

while on the normal nxginx we have:

'REQUEST_URI' => string '/'
'PHP_SELF' => string '/index.php'
'SCRIPT_FILENAME' => string '/usr/share/nginx/current/web/index.php'
'SCRIPT_NAME' => string '/index.php'

To fix this, one needs to set this into the config:

'request' => [
    'scriptUrl' => '/index.php',
],

I don't know if this limitation should also be addressed in google cloud, like setting the root of htdocs, but from yii point of view I think we are fine with this solution, right?

Yes.

For the assets part, google supports writing files using stream wrapper gs://bucket_name/desired_object_name.

As most of the filesystem access functions are mapped, I think the original yii2 AssetManager class should work, I will try it and come back with needed changes.

Documentation: https://cloud.google.com/appengine/docs/php/googlestorage/

Thank you!

Any news on this? I've been looking into building a Yii2 app with autoscaling through Google App Engine (or Amazon Elastic Beanstalk), but it doesn't appear to be working out of the box as of yet.

@iadj not really. Haven't touched it. If you want to dig into it, feel free to do so.

@samdark Managed to get Yii2 working perfectly with Google Cloud using a Managed Compute Instance and a Load Balancer simply by configuring Redis for both the Session and Cache management!

That's good news. Can you share something like a manual on how to do so? I bet it would be interesting for many people and it worth including into https://github.com/samdark/yii2-cookbook

@samdark Yes absolutely! Will write up a small guide this week.

Thank you!

Nice! I'll close this issue. Would link to the cookbook later from the guide on performance.

The directory is not writable by the Web process: /base/data/home/apps/some_adress/frontend/web/assets

и что делать?

Нужно дать пользователю веб-сервера права на запись

EN: web server user should have write permissions

Раньше вообще нельзя было писать. Теперь вроде можно: https://cloud.google.com/appengine/docs/php/googlestorage/

EN: It wasn't possible to write in GA. Now it is possible: https://cloud.google.com/appengine/docs/php/googlestorage/

А как разрешить запись? Ссылка выше на запись в облако, а YII сам пишет к себе в папку кеш и т.п.

EN: so how to enable writing? The link above is about writing into cloud storage but Yii itself writes to cache etc.

Сам к себе не пишет, если не использовать файловый кеш и файловые логи.

EN: Yii isn't writing anything if you aren't using file cache or file logs.

А как можно отключить их?

EN: how to turn it off?

Это всё есть в документации. Читайте.

EN: it's in the docs. Read it.

Затупил, разобрался. Сейчас встрял на том, что не получается применить миграции в cloud sql. Из cloud shell недоступен pdo_mysql,а php,ini работает только для инстанса. Может кто то знает как это делается?

EN: I did it. Now the problem is that I have no idea how to apply migrations in cloud sql. There are no pdo_mysql in cloud shell and php.ini is for an instance only. Any idea how to do it?

Guys can we please talk English if the OP is written in English?

@iadj translated.

Was this page helpful?
0 / 5 - 0 ratings