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

GAE php5.5 #7

Closed
nickypeh opened this issue Feb 27, 2015 · 17 comments
Closed

GAE php5.5 #7

nickypeh opened this issue Feb 27, 2015 · 17 comments

Comments

@nickypeh
Copy link

Hi,
I encounter a problem for the new Google App Engine runtime for the php 5.5 that supported Curl now.
Previously, in PHP 5.4, everything is running fine for the development and production as well.

After adjusted to PHP 5.5, it seems like the error logging is having some error.
First, it seems like it cannot detect our environment using the 'hostname' where i have to explicit set it as follow :

$env = $app->detectEnvironment(function(){
      if (strpos($_SERVER['HTTP_HOST'],'.') === false) {  
          return 'local';  
      }
      return 'production';
    });

However, with this, it could detect it is in local mode now but it will have this error now.

Error in exception handler: The stream or file "/GAE/server/app/storage/logs/laravel.log" could not be opened: failed to open stream: No such file or directory in /GAE/bookme/GAE/server/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84

If i revert it back to 5.4 and everything works fine again. I also make sure my storage folder got all the read and write access.
Any advise on this ?

Thanks.

Regards,
Nick

@shpasser
Copy link
Owner

I think that the issue is fully related to the environment detection.
The only supported log handler for GAE is syslog. According to the posted error message the log handler used is using files, and was configured using app/start/local.php. When running on GAE the production environment is supposed to active and the log handler is configured using app/start/production.php, which configures log to use syslog handler.

I managed to run my test app on GAE without applying any changes.

I would suggest to revert the bootstrap/start.php to the original coding:

$env = $app->detectEnvironment(array(

    'local' => array('homestead'),

));

or something else, but using the same format i.e. 'env-name' => ['host1', 'host2', ...].

After that, please capture the error via GAE log and post it here for further discussion.

Best,

Ron.

@nickypeh
Copy link
Author

Hi Ron,
Just to make sure, you did try it on the runtime: php55 for the app.yaml right ?

This is my bootstrap/start.php which I converted back to the original files

$env = $app->detectEnvironment(array(
    'local' => array('Mac-mini.local'),
));

Some how. when i try to print out my monolog to get the current environment, it is still in production mode even though i set it to my local machine. I double check with my machine hostname to make sure it is not misspelled. Take note that it is working on php5.4 before the updates carried out by GAE.

Please advise.

Regards,
Nick

@shpasser
Copy link
Owner

I used the following app.yaml file to push my app to GAE:

application:    test1-app
version:        1
runtime:        php55
api_version:    1

handlers:
        - url: /favicon\.ico
          static_files: public/favicon.ico
          upload: public/favicon\.ico

        - url: /packages
          static_dir: public/packages

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

skip_files:
        - ^(.*/)?#.*#$
        - ^(.*/)?.*~$
        - ^(.*/)?.*\.py[co]$
        - ^(.*/)?.*/RCS/.*$
        - ^(.*/)?\.(?!env\.php).*$
        - ^(.*/)?node_modules.*$
        - ^(.*/)?_ide_helper\.php$

and I'm using homestead (via vagrant) for my local environment.

Anyway I would suggest you run PHP code like this one:

<?php 
var_dump(gethostname());

in order to obtain the correct hostname.

If you could send me a sample app code having the same issue I will be able to investigate.
In the mean time I would suggest to use dd(var_name), while putting it in different places in the code to examine variables values. Another thing is to try creating a new Laravel 4 app, setup it for GAE and see if the issue reappears.

Best,

Ron.

@nickypeh
Copy link
Author

Hi Ron,
I tried with the simplest project but somehow the issue is reappearing.
I have created a repositories in github as follow for the sample app code in order to debug:
https://github.com/nickypeh/gaelaravel55

The boostrap/start.php local files are using my PC hostname. I doublecheck again with the

PHP Code

<?php 
var_dump(gethostname());

and I am getting the same hostname.

Hence, I tried to switch between runtime 5.4 and 5.5 with the same settings and apparently, the 5.4 could detect my environment. For a further testing, I change the $env to wrong local name in the bootstrap/start.php in PHP 5.4 runtime and it could switch to production which means, the 5.4 is working as expected but not the PHP 5.5 runtime.

I have configure the route '/env' to printout the current environment.
Please help to test it out and let me know your input on this.

Thanks.

Nick

@shpasser
Copy link
Owner

Hi Nick,
Just finished deploying your app on GAE, I had to change the app-id in app.yaml and GCS bucket name in php.ini in order to make it work, please take a look:

http://test-sql-l4.appspot.com
http://test-sql-l4.appspot.com/env

From my perspective the production environment works Ok in both PHP5.5. and PHP5.4.

Then I changed the bootstrap/start.php to include homestead instead of ARMSs-Mac-mini.local as a local environment and tested your app on homestead VM and also using dev_appserver.py and could not see any errors.

In my opinion there should be something in the workflow that you are using preventing the app from working properly or maybe something about your assumptions regarding the app. Please send me the exact set of commands, behaviours, assumptions and outputs you have in your workflow (including the deployment command, like appcfg.py update ./), so I could try to pinpoint the issue.

Best,

Ron.

@nickypeh
Copy link
Author

Hi Ron,
I guess going into production is not getting me any problem as it will detect in production.
For me, the concern is at the local environment. As it can't do logging and selecting db based on environment unless I manually change DB settings.
Did you try on ur pc without using the homestead VM but use the 'hostname' instead?
My steps are quite easy. It would be great to send u the deployment command but I am just running the app folder locally using the GoogleAppEngineLauncher which I didnt use any of the deployment command at the terminal.

There is only one thing I change from PHP5.4 to PHP5.5,

application:    gaelaravelsql
version:        1
runtime:        php55   --> changing this from php to php55
api_version:    1

handlers:
        - url: /favicon\.ico
          static_files: public/favicon.ico
          upload: public/favicon\.ico

        - url: /packages
          static_dir: public/packages

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

skip_files:
        - ^(.*/)?#.*#$
        - ^(.*/)?.*~$
        - ^(.*/)?.*\.py[co]$
        - ^(.*/)?.*/RCS/.*$
        - ^(.*/)?\.(?!env\.php).*$
        - ^(.*/)?node_modules.*$
        - ^(.*/)?_ide_helper\.php$

Hence, I just relaunch the app using the GoogleAppEngineLauncher and use the '/env' route, and it just echo me back with production environment.

To conclude from PHP5.4 to PHP5.5, only one changes made which is the app.yaml from php to php55.
Nothing else is changed. Switching back to PHP5.4 by removing the '55' in the app.yaml and everything works fine for detecting environment. At PHP5.4, I could do logging in the storage/logs/laravel.log as well.

@shpasser
Copy link
Owner

I downloaded the GoogleAppEngineLauncher and tried to run the app. It appears that gethostname() returns localhost:8080 for php55, so that is the new hostname you have to fill in bootstrap/start.php in order to have the environment detection to work properly.

But still there is another big issue, on which I cannot help you, in php55 environment the local file system is read-only, meaning all the data previously written to app/storage directory including session data, compiled views and more is not allowed to be written there anymore.

Currently I don't know if this behaviour can be changed easily.

I suggest using Vagrant + VirtualBox + Homestead VM for local development.

Best Regards,

Ron.

@nickypeh
Copy link
Author

nickypeh commented Mar 2, 2015

Hi Ron,
Thanks for the feedback. Was busy over the weekend. I will try on using your suggestion for local development. However, for local development using Homestead VM, everything will be the same like in GAE environment ? With php54, everything is working fine in the local environment as if it is in GAE environment but sadly php55 changed the local file system to read only.

Thanks.

Regards,
Nick

@shpasser
Copy link
Owner

shpasser commented Mar 2, 2015

Hi Nick,
I should clarify a little bit on the issue:

  1. Both GAE production environments, php45 and php55, have read-only file systems, meaning you can update the file system contents while deploying the app, but not while running on GAE.
  2. The package detects when the app is running locally vs in production mode and sets the storage path appropriately. When running on GAE a default GCS bucket is used as read-write storage.
  3. It seems that in contrast with local php45 dev server local php55 dev server does not allow writing to the local file system. In particular it does not allow writing to app/storage directory, which is used by default by Laravel to store the compiled BLADE views etc.
  4. You can use the homestead local environment to develop your app and then deploy and try it on GAE. The package is capable to apply local and production needed changes dynamically.
  5. The only drawback is that not all the file operations are enabled on GCS buckets, so I suggest you consult the GAE documentation in order to understand what is really supported.
  6. Some of PHP functions have to be enabled via php.ini to run on GAE.
  7. Since PHP55 support for GAE is very new I suppose there will be more than one-two behavioural changes and bugs.
  8. As for me, I do the development on my local homestead environment and I test on GAE. Of course this involves using different providers for mail, queue and database. The providers are switched automatically according to the local environment files and GaeSupport knows when not to alter them.
  9. The support to run migrations on Cloud SQL when running in local environment is on the way. BTW it is already incorporated in GaeSupportL5 package.

Hope this helps,

Ron.

@nickypeh
Copy link
Author

nickypeh commented Mar 3, 2015

Hi Ron,
Thanks for the detail information. This has been useful.

Anyhow ,a quick question for u, do you have any example code to provide upload handling with laravel and gae? I notice that in GAE, if we want to upload picture or any files to the gae bucket, it is quite different.

Thanks.

Regards,
Nick

@shpasser
Copy link
Owner

shpasser commented Mar 3, 2015

In general you could use something like proposed here:

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

But if you'd like my opinion on Laravel friendly way, I could get back to you in couple of days after some testing.

@nickypeh
Copy link
Author

nickypeh commented Mar 4, 2015

Hi Ron,
That could be great if you could come out with laravel friendly way .

In the mean while, I would try to use on the proposed method.

Thanks.

Regards,
Nick

@shpasser
Copy link
Owner

I was very sick last week, it will take some time to respond.

@nickypeh
Copy link
Author

nickypeh commented Apr 9, 2015

Hi Ron,
You can close this one as I found a workaround for the file uploads.
Thanks for the help.

@shpasser
Copy link
Owner

shpasser commented Apr 9, 2015

Hi Nick,
Thanks for your patience.
Actually I do have something in work about the issue, just couldn't get it right till now.
In order to use the same code in local and production environments I'll have to make
some changes to GaeSupport's Application class and create an alternative FormBuilder
with some changes. I'm going to include the feature in the next version, which will include
also some of the performance optimization features I added lately to GaeSupportL5 package.
Sorry for the delay.

@shpasser
Copy link
Owner

Some interesting facts about the new GAE SDK:
https://gae-php-tips.appspot.com/2015/03/03/file-system-changes-in-app-engine-1-9-18/

I would recommend to take a look specifically at:

To make the filesystem read/write, add the following to your php.ini file.
google_app_engine.disable_readonly_filesystem = 1

@shpasser
Copy link
Owner

Since the relevance of illuminate/html is not that high, I decided to postpone the upload related activities, sorry, have to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants