How can I use autoload.php in google app engine (php)? - php

I'm new to app engine and trying create a php app from a sample code.
Can anyone please tell me what is the use of
require_once DIR . '/vendor/autoload.php';
Is this set of libraries we need to download?
I'm developing/test locally and deploying in to gcloud project using 'gcloud app deploy'
I can use
use google\appengine\api\users\User;
but I cannot use
use google\cloud\storage\StorageClient;
Fatal error: Class 'google\cloud\storage\StorageClient' not found in C:\Users..
Is there a component to install for cloud storage?
Thanks

Thank you for your advice.
ACtually even after deploying project in to my google project I get the
same issue.
That's why I thought it's something to do with gcloud app engine setting.
Because according to my understanding in google app engine all the
libraries are available by default. Aren't it?
This is my project and I get the same error.
https://assignment2-s3682248.appspot.com/
https://rb.tc/4YY3B#https://assignment2-s3682248.appspot.com/
Chears
Sam
On Fri, Sep 27, 2019 at 4:27 AM 'George (Cloud Platform Support)' via
Google App Engine wrote:
As PHP scripts run relative to the current path, not to the path of
script itself, you can use DIR to change this behavior, so that include
refers to the script's own path, as a result.
StorageClient not found error is likely due to the absence of Cloud
Storage Client Libraries
https://cloud.google.com/storage/docs/reference/libraries, which you'll
have to install.
This discussion group is oriented more towards general opinions, trends,
and issues of general nature touching the app engine. For coding in PHP,
and program architecture, as well as importing Cloud Storage Client
Libraries, you may be better served in dedicated forums such as
stackoverflow, where experienced programmers are within reach and ready to
help.

I'm really not sure if your question has already been answered (since I see you posted an answer that a GCP support agent gave you) but you didn't accept it.
If you are new with App Engine/PHP I would recommend to follow the documentation's quickstart to get a simple project up and running and then you can start modifying it accordingly to your requirements.
From the questions I could find on your post, how to use the "autoload" of composer with DIR and how to use the Cloud Storage lib in your app. I recommend to carefully read the documentation I have referenced (the three are from the same documentation but on specific parts) which describes the step by step on how to build your application.

Related

Is there a simple way to reduce the AWS PHP SDK to use only S3?

I would like to know is there a simple way to reduce the AWS PHP SDK to use only S3 ? I tried to delete certain directory but there are so many it will take an incredible time, and I have many errors depending on the files I delete (21,6Mo - 2 368 elements) ?! Is it possible to know the architecture of the basic files necessary to use only S3 with the SDK PHP please?
I found old posts on this subject but the file structure has changed and they are no longer current.
The complete SDK is very heavy with a lot of files that I don't need to keep my sources with an optimization in reasonable size.
Thanks for your help
Unfortunately to use the SDK you will need to use the entire directory (and all of its individual dependencies).
Whilst you could prune individual directories and files you would then be responsible for maintaining this, including new features which may require additional classes
Best practice for pulling in the SDK is to use the composer dependency manager.
If you were looking for a lighter version you would need to look for someone else's implementation or look at implementing your own library to interact with the AWS S3 API endpoints.
The SDK itself now has a (beta) feature to help you out. Check out https://github.com/aws/aws-sdk-php/tree/master/src/Script/Composer
Basically you require the framework with composer, then specify a script to remove unused services, then define the services you want to keep based on their root namespace.
The example from the page is given below
{
"require": {
"aws/aws-sdk-php": "<version here>"
},
"scripts": {
"pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices"
},
"extra": {
"aws/aws-sdk-php": [
"Ec2",
"CloudWatch"
]
}
}
Nicolas and Chris,
A Wordpress plugin-related blog entry led me to this S3 SDK Git project by developer Ian Jones that may help resolve this for you, or others in future. The blog article explains the background and reasoning behind the code.
It's a script he wrote for downloading the AWS PHP SDK v3, stripping it down to the relevant S3 functionality, and then applying a custom namespace to avoid potential clashes.
Hoping to try this myself soon, but also for use with the Rekognition API (but I'm at beginner level!).
https://gist.github.com/ianmjones/55eb1ace80517f951e392b95a65f277b
Regards,
Graham
I would highly recommend https://async-aws.com/. You can install each component separately. Maybe it not cover every AWS feature, but S3 is supported for years.

how to create configure and depoly Php app on openshift v3.x

We as developers believe that Openshift v2 was a great platform for developing and deploying apps, now the Life of v2 is going to be end and the v3.x is arrived to play its role.
As a new to v3 architecture, I would say this is bit difficult to get started as easy as v2 was, I have some questions to ask in first place :
In v2 we can create an application and there comes a link to clone the repo locally, how can we create a PHP application on v3 without Github repo and clone that to local repo so that source may be private?
Adding databases on v2 were much easier, but on v3 it is like a nightmare for developers like me, How can we add MySQL DB to our PHP application on v3?
In v2 we make a change to source code, commit and push the app was live in short, How can we commit new changes in v3?
these are the basic questions which must be answered, any resource would be a life saving.
(1) To avoid using GitHub, or any other Git repository hosting service, you need to use a binary build. Although the post is about Django and Python, you can see the steps for using a binary build in:
https://blog.openshift.com/migrating-django-applications-openshift-3/
(2) To add a database, you go Add to Project, find the database you want to use there and create it. Then set the environment variables against the deployment configuration of the front end application so it knows where the database is and what login credentials are. An example of that can be found in:
https://blog.openshift.com/adding-database-openshift-online-3/
(3) If using a binary build as you seem you will want to due to (1), then you start a new build and tell it to use the code from your local directory. This is explained in same post given for (1).
Also suggest you work through example application in:
https://www.openshift.com/promotions/for-developers.html
This will give you further background on using OpenShift version 3.
If you want to keep the same workflow you had in OpenShift v2 (commit/push/live), sign up for a free account on GitLab.com or Bitbucket.com which both include free private repos (or bite the bullet and pay for an account on GitHub.com).
Then, check out Graham's post on best practices for using private git repos with OpenShift v3, which links to several guides on the subject: https://blog.openshift.com/private-git-repositories-part-1-best-practices/
As for the DB, you can add the database after the fact as Graham described (add a database to your project, tell your PHP application which variables to look for, then set those environment variables for your PHP app's deployment config), or you can write a re-usable template to deploy your application to any OpenShift cluster that includes the PHP app and database along with their configuration (see CakePHP template examples). I prefer creating a template for my apps with v3, but maybe I'm crazy :)

cakephp on google cloud

I found this question which is pretty old: Is it possible to deploy cakephp applications on google app engine?
Some people stated, that it's most likely at least complicated - someone in the comments stated, that google supports php now(2013). Regarding to the google documentation: https://cloud.google.com/appengine/docs/php/ it's still beta.
So my question is: did someone ever successfully deploy a cakephp application on google app engine? Is it now(2015) possible to deploy a app there without too much problems?
"officialy" the CakePHP is not supported. You may find several steb-by-step howto's where is the deployment explained:
http://dev-mcconnell.blogspot.sk/
http://aymanrb.blogspot.sk/2013/05/cakephp-deployment-on-google-app-engine.html
However, when our customer requested to have CakePHP within his AppEngine, we decided to deploy Google Compute Engine linux VPS with some limited resources (you do not need that much resources if you do not expect huge amount of visitors), and we installed Apache, PHP and MySQL onto this VPS and we run CakePHP application from there.
So generally, the use case above is not an AppEngine deploy, but a deploy within Google Cloud services.

How to reference nested requires in app.yaml for App Engine PHP

I have a index.php with a
require 'myfolder/folder/lib1.php';
So in app.yaml I reference:
- url: /myfolder/folder/lib1.php
script: myfolder/folder/lib1.php
but this lib1.php does another require 'lib2.php'; at same folder level /myfolder/folder/. So it trows error 500 because it can't find lib2.php.
How can I properly reference them both in app.yaml?
Your app.yaml file is for routing requests from incoming URLs to the initial script you want to use to process the request.
You don't need to add routings for each and every *.php file that you want to include from one script to another.
For example, look at the app.yaml example for running wordpress. It just has the URLs that clients will access, but not all of the php scripts used by wordpress.
The problem you face is most likely independent to Google App Engine. On Google App Engine, the standard rules of PHP file-inclusion still applies. The only potential difference here is that the files are read-only (but that should not pose any problems in your case).
So if lib1.php requires lib2.php you need to require the later before you require the other. That is standard PHP behavior:
require 'myfolder/folder/lib2.php';
require 'myfolder/folder/lib1.php';
To learn more what exactly caused the 500 error on Google App Engine, consider downloading the log and look into it. This is also independent to Google App Engine, because that is the best suggestion one can give with any webserver on 500 errors.
The error 500 was thrown basically because Google App Engine for php doesn't support CURL extension used in the Facebook php SDK. Nothing related to app.yaml includes.
I forked the official fb sdk git and I'm patching a solution right now.

Google App Engine phpBB

I was wondering whether it's possible to install a phpbb instance to Google App Engine since I saw this: https://developers.google.com/cloud-sql/ and this: http://php-apps.appspot.com/
Standing up a phpBB instance on Google App Engine and Cloud SQL.
They seem to have done it. I am trying to look for a Youtube tutorial.
I am not that expert but as far as I know GAE is not natively designed for PHP.
You can definitely use this instruction as a basis on How to Add phpBB with Jelastic service. The given instruction seems to present a pretty easy start.
Yes, it's possible -- see: http://fredsa.allen-sauer.com/2013/07/standing-up-phpbb-instance-on-google.html
(App Engine now has a PHP runtime: https://developers.google.com/appengine/docs/php/).
Maybe. It's hard to say. It's possible to run SQL as well as PHP via Quercus (JVM). The limitations you'll run into are if phpBB depends on any specific behavior that App Engine does not support, such as native filesystem access. I haven't heard of anyone trying phpBB on GAE before, so if you took a shot at it, you'd be blazing a trail!

Categories