Coder Social home page Coder Social logo

affordablemobiles / gserverlesssupportlaravel Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 18.0 1.56 MB

Run Laravel on Google Serverless

License: MIT License

PHP 99.87% Makefile 0.13%
laravel gae php google-cloud google-appengine appengine-php appengine cloud-run gcr google-cloud-run

gserverlesssupportlaravel's People

Contributors

dstretton avatar flexgrip avatar iamacarpet avatar lew-blount avatar matthewnessworthy avatar mhiran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gserverlesssupportlaravel's Issues

us14 not found

image

I tried to run on google cloud but it is not finding the us-central1 region that is called us14

Memcached

Hello,

In my GAE Standard + Laravel app, I'm currently running a standalone redis instance (on GCE). It sucks. The VPC connector was unreliable, so I'm having to connect to it via the public IP. It sucks.

The original package that this repo was based on actually started implementing the native memcached from GAE. Does this repo plan on doing that?

I keep thinking if we just write a simple driver for memcached it might work. Curious what your thoughts are...

Storage Directory on App Engine

Currently, we've got the gae_storage_path() function which we're using in the config files instead of storage_path().

It'll be good to swap this instead for replacing the root Application class with our own extended version like the old library, setting the storage path internally to /tmp/laravel/storage.

We should check if the directory exists and if it doesn't, scan the directory structure of the normal storage directory, then re-create it in the new /tmp location.

For the custom view service provider, we'll need a way to re-create the old storage path, to keep it as it was/is.

Review gae_realpath() requirement on PHP 7.2 runtime

PR #36 highlighted the presence of gae_realpath() calls in the Laravel 5.5 version.

Since this no longer runs on the PHP 5.5 runtime, this should no longer be required.

Review the usage and see if it & associated storage code can be removed.

batch-daemon-failures taking up space on /tmp

From @flexgrip

Has anyone using this package had issues with instances running out of memory? I don't think its this package, it might be one of the dependencies. But on gae standard, I keep seeing Exceeded soft memory limit of 512 MB with 521 MB after servicing 95 requests total. Consider setting a larger instance class in app.yaml.

I tried to dig around the instances to see what was going on. So I made a little endpoint that would return the contents of the /tmp directory. Because I realized either the runtime can take up space in memory or /tmp can put files in memory there. The tmp directory wasn't taking up much disk space. But then I noticed this:

/tmp/batch-daemon-failure - 0MB
/tmp/batch-daemon-failure/. - 0MB
/tmp/batch-daemon-failure/.. - 0MB
/tmp/batch-daemon-failure/failed-items-21 - 34.3MB
/tmp/batch-daemon-failure/failed-items-22 - 57.41MB
/tmp/batch-daemon-failure/failed-items-23 - 37.12MB
/tmp/batch-daemon-failure/failed-items-24 - 44.12MB
So those batch-daemon-failure files are starting to take up quite a bit of space. I grep'd around for it and found a reference to it in the google-cloud-core php package.

Anyway, that leads me back to here. The only package I run that imports that cloud core package from google is this one :/

I don't know if this problem existed in the versions prior to L6. I dunno. I'm out of ideas. At this point, I'm trying to see if there's an env var to turn off the batch daemon thingy (I don't even really know what it does).

Any info would be appreciated. Maybe that package isn't needed or something?

I think it's likely related to either logging or OpenCensus tracing, as the batch daemon stuff was all related to using these tools in App Engine Flex.

We'll look into it and let you know.

Example Configuration Files

We need some example app.yaml and .env files with documentation.

I don't think it'll be a good fit to auto-generate them from the artisan setup command if we want to easily be able to switch between Standard and Flexible, as that was more suitable as a one-time thing.

Create a samples folder with some examples?

StackDriver Trace Integration (OpenCensus)

Integrate StackDriver Trace via OpenSensus for Laravel 5.5, which supersedes #3

We'll be using the opensensus PECL extension that is included in App Engine on both Standard & Flex, which will allow trace hooks without needing to modify code to add trace points everywhere.

Unknown App Engine Region Code: europe-west2-a

I used Google App Engine Flexible Environment and I get error:

PHP Notice: Exception: Unknown App Engine Region Code: europe-west2-a in 
/app/vendor/a1comms/gae-support-laravel/src/A1comms/GaeSupportLaravel/Integration/TaskQueue/Client.php:61

Laravel 6?

Great pack, but do you plan to upgrade to Laravel 6 in the nearest future?

jsonPayload Log Support on the Standard Environment

Building on the async submit functionality for the Trace API referenced in #3, we should try to build in support for the jsonPayload style logs that Google's custom MonoLog handler supports on the Flexible Environment.

Can we build our own custom log handler and submit all logs without context via the standard syslog method, which should hopefully catch all fatal errors, while submitting logs with a jsonPayload via the Push Queue API to our async processor?

One thing we'll have to watch out for is the maximum POST size, as even on a large trace we were having to split into multiple chunks - does this mean it'd be unsuitable to save all the logs up until the end of the request and submit them then?

Handle Configuration Cache

Handle the "artisan config:cache" command for deploying to App Engine.

Testing it locally, it puts full paths from the development/build environment into the "storage_path" locations.

We'll need to overcome this - do we:

  • Add event listeners?
  • Detect the execution is a config:cache and make changes?
  • Have our own artisan command for this instead?

Remember the note from the documentation:

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.

https://laravel.com/docs/5.5/configuration#configuration-caching

Lumen Support

Once everything else is in place, make the required changes to make sure the package works with Lumen as well as Laravel, as with the previous version.

IAP Style Service-to-Service API Authentication

Create an interface for IAP style Service-to-Service OAuth2 authentication.

For use when using IAP isn't an option because it can't be turned on/off seamlessly for different service/versions.

  • A middleware to validate incoming requests
  • A class (Guzzle middleware?) to generate JWT bearer tokens for outbound requests to other services.
    • Guzzle middleware should be re-usable to make requests via the real IAP.

Bearer token should include the Client ID as required by IAP and the middleware that verifies the auth should check this too.

https://cloud.google.com/iap/docs/authentication-howto#iap_make_request-php

Prepare command outdated

Prepare command "php artisan gae:prepare flex" is outdated as laravel now uses new version of Dotenv

Batch Daemon on the Standard Environment (GAE)

It would be great to have the batch daemon on the Standard Environment, as not only would it support better async submission of both logs & trace entries, it would also allow us to use Stackdriver Debugger with live breakpoints/logpoints, etc.

So far, we tested it on Flex but we've struggled to enable it on the Standard Environment.

Requirements could not be resolved

When I did composer update, I got a error message.

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - a1comms/gae-support-laravel dev-php72-laravel55 requires tomwalder/php-gds dev-grpc -> no matching package found.
    - a1comms/gae-support-laravel dev-php72-laravel55 requires tomwalder/php-gds dev-grpc -> no matching package found.
    - Installation request for a1comms/gae-support-laravel dev-php72-laravel55 -> satisfiable by a1comms/gae-support-laravel[dev-php72-laravel55].

tomwalder/php-gds has not "dev-grpc" version now.
https://packagist.org/packages/tomwalder/php-gds

Several setup questions

Hello again,

I was going to use your package solely so that I can get Cloud Tasks to work as a queue driver. But then I had a bunch of questions about how I might use other portions of it. So I'm going to place these below. If you have time, I'd love to know what you think. I noticed other tickets about example configurations and cloud build configs. Maybe this can help clear those up. I could even PR some to you if you think it would help.

Current setup

You should know I already have an existing Laravel 5.8 installation on GAE standard. And I would prefer not to use flex/docker. I do not use cloud build and I could not figure out how to get cloud build to compile my node assets while still using GAE Standard.

What I have working:

  • Vanilla deploy without cloud-build
  • Cloud SQL as DB
  • Stack driver logging (but there don't seem to be many logs or maybe its not working)

What I don't have working:

  • Task queues using cloud tasks
  • Blade view compiler (not sure what is getting compiled, if anything)
  • I have to pre-build my JS before deploying

Questions

  1. How do you currently compile node/js assets for a deployment? I have to run yarn run production before deploying JS changes
  2. Since I am not doing anything regarding blade view compilation, does that mean that its just running everything at runtime? Not sure how its currently working since I haven't touched the blade compiling
  3. How are you running cron? I setup a cron.yaml and pointed it at an endpoint, but it doesn't really seem to do much.

Thanks!

Ahead of Time Blade View Compilation

Since App Engine is deploy once, run many times on many instances, there may be some performance benefit to ahead-of-time compilation of all of the blade views as deploy time.

This may not be standard in Laravel, as a deployment to a standard LAMP stack where the files reside on disk have the expectation that files can be changed and the framework will adapt dynamically.

We'll investigate if we can have an artisan command to do this as part of our Cloud Build push-to-deploy pipeline, creating the on-disk cache files that would then become read-only and should be valid for the lifetime of that version.

Once that's done, we should also look to see what the framework is doing to allow the files to be refreshed by invalidating the cache when the change on disk in the normal LAMP use case, as there may be some disk operations we can nullify here, hopefully reducing request latency where disk I/O latency is high on App Engine.

Cloud Trace API Support

Google are in the process of merging a new interface to interact with Cloud Trace googleapis/google-cloud-php#456

Once their PR is merged into master, we need to introduce Trace support here.

We'll start out with the Laravel provider here: https://github.com/chingor13/php-test-apps/blob/master/laravel/blog/app/Providers/GoogleCloudProvider.php

Keep it using AsyncReporter and QpsSampler on Flexible, but modify it so it'll detect the Standard Environment and revert back to our old method of using Push Queues to do an async submit as the latency is a lot lower, plus use the AlwaysOffSampler, as we only want to sample when App Engine wants us to which it'll signal by sending o=1 in the header.

To this end, we'll need to write our own Reporter interface that'll utilise the Push Queue API.

Since using the Push Queue method will use more chargeable resource, we should publish our cost tuned Go microservice that can be deployed to do the async work from this library.

Although, should we write the URI handlers to do the same work in here for people who don't want to utilise this method? Perhaps if they are super low volume and find it easier to stay within the free tier that way?

SIGSEGV on App Engine PHP 7.4

Trying to run this on PHP 7.4 on App Engine, pretty instantly getting SIGSEGV logged from php-fpm

Trying to debug, can re-create in a blank folder, get composer to install the latest "google/cloud" and in public/index.php:

<?php

require __DIR__.'/../vendor/autoload.php';

use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Logging\PsrLogger;

(new LoggingClient())->psrLogger('exception')->error('test',[]);
die('logged');

You'll get SIGSEGV, then if you change it to:

<?php

require __DIR__.'/../vendor/autoload.php';

use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Logging\PsrLogger;

(new LoggingClient(['transport' => 'rest']))->psrLogger('exception')->error('test',[]);
die('logged');

It works again :).

Looks like the gRPC binary module / PHP extension is broken: have raised with Google.

Simply setting the transport to 'rest' in one place isn't really a fix, as everything defaults to gRPC everywhere, it's just useful as a PoC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.