PHP Web Apps on Google Cloud
Bhavik Shah
Software Architect. Technologist. Evangelist.
Introduction
PaaS Clouds with PHP!
Google App Engine
Scalable, Reliable & Fast PaaS
* Experimental
PHP Support.
Why PHP?
Built for Web
Easy to Learn
Most Requested
<?php
echo "Hello World!";
?>
PHP
Frameworks
Rapid
Most popular
75% of...
Symbiotic relation
Google provides a great platform for PHP
PHP brings a popular language to Google.
PHP on App Engine
Image Courtesy: Google IO 2013
How to PHP?
Installation
Python 2.7
Google App Engine SDK 1.8.4
PHP (Thread Safe) 5.4
Remember:
Add each of it to your OS’s PATH varia...
Sign up
Google provides a great platform for PHP
PHP provides a language to Google.
Create application
Google provides a great platform for PHP
PHP provides a language to Google.
Creating application locally - 1
app.yaml
application: <your-app-id>
version: 1
runtime: php
api_version: 1
threadsafe: tr...
Creating application locally - 2
index.php
<?php
echo "Hello World!";
?>
PHP
Creating application locally - 3
php.ini
; php.ini
google_app_engine.enable_functions = "php_sapi_name,
php_uname, phpinfo...
Creating application locally - 4
phpinfo.php
<?php
echo phpinfo();
?>
PHP
Deploying
Executing Application (Runs Locally)
dev_appserver.py --php_executable_path=
C:phpphp-cgi.exe <application id>
U...
Features
Cloud SQL
MySQL 5.5 in Cloud
Automatic Backups
Automatic replication
Geo-Located with App
Resource Limit
Maximum Request S...
Cloud Storage
Built in Stream Wrappers allowing use of
file api’s like file_get_contents();
$fp = fopen("gs://my_bucket/so...
Functions disabled by default
Manual enabling possible via php.ini
gc_collect_cycles(), gc_enable() and gc_disable()
getmy...
Disabled Functions
Permanently disabled
disk_free_space()
diskfreespace()
escapeshellarg() and escapeshellcmd()
exec()
fso...
Limits on PHP
Limit Amount
request size 32 megabytes
response size 32 megabytes
request duration 60 seconds
maximum total ...
Other Services
Application Identity
Logs
Mail
MemCache
URL Fetch
User Authentication
Task Queues
Web App : URL Shortener
Use Bootstrap with PHP
Recommended: CodeIgnitor or Yii
Source Code available at https://github.com...
Demo
References & Other details
developer.google.com
venturebeat.com
udemy.org
Disclaimer: All images & logos used in
the prese...
Questions?
Thank you for your attention
Bhavik Shah
Twitter: bhavik1st
Email: bhavik1st@gmail.com
www.linkedin.com/in/bhavik1st
Upcoming SlideShare
Loading in …5
×

GDG DevFest 2013 - PHP Web Apps on Google Cloud

8,167 views

Published on

Google GDG DevFest 2013 PHP Web App on Google Cloud (Google App Engine) - By Bhavik Shah. Presented on 21st Sep 2013 in Pune, India

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,167
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Image Courtesy: Wikimedia, http://gdg-generator.appspot.com/, GDG
  • PaaS - Platform as a Service, Web Hosting Scalable - Storages, Databases and Services Reliable - Distributed, Redundancy Languages - Python, Java, Go and PHP * PaaS uses same infrastructure that Google Applications Use. Reliability zero downtime Google IO 2013 May 14 2013 San Fransisco.
  • Despite node and Ruby http://en.wikipedia.org/wiki/PHP#cite_note-W3Techs_usage_statistics-79 http://w3techs.com/technologies/overview/programming_language/all stood for  Personal Home Page , [4]  it now stands for  PHP: Hypertext Preprocessor , 
  • Despite critic of PHP about language inconsistency, scalability, performance.
  • Multiple data centers Memcache optimizes Mysql library ..
  • PaaS - Platform as a Service, Web Hosting Scalable - Storages, Databases and Services Reliable - Distributed, Redundancy Languages - Python, Java, Go and PHP * PaaS uses same infrastructure that Google Applications Use. Reliability zero downtime Google IO 2013 May 14 2013 San Fransisco.
  • PaaS - Platform as a Service, Web Hosting Scalable - Storages, Databases and Services Reliable - Distributed, Redundancy Languages - Python, Java, Go and PHP * PaaS uses same infrastructure that Google Applications Use. Reliability zero downtime Google IO 2013 May 14 2013 San Fransisco.
  • PDO $db = new PDO(&apos;mysql:unix_socket=/cloudsql/hello-php:my-cloudsql-instance;charset=utf8&apos;,   &apos;&lt;username&gt;&apos;,   &apos;&lt;password&gt;&apos; ); mysql_connect $conn = mysql_connect(&quot;:/cloudsql/hello-php:my-cloudsql-instance&quot;, &quot;&lt;username&gt;&quot;, &quot;&lt;password&gt;&quot;); mysqli $sql = new mysqli(null, &quot;&lt;username&gt;&quot;, &quot;&lt;password&gt;&quot;, null, null, &quot;/cloudsql/hello-php:my-cloudsql-instance&quot;);
  • PaaS - Platform as a Service, Web Hosting Scalable - Storages, Databases and Services Reliable - Distributed, Redundancy Languages - Python, Java, Go and PHP * PaaS uses same infrastructure that Google Applications Use. Reliability zero downtime Google IO 2013 May 14 2013 San Fransisco.
  • $client = new Google_Client();$service = new Google_UrlshortenerService($client);$taskDone = false; if (isset($_GET[&apos;url&apos;])) { // Start to make API requests. $url = new Google_Url(); $url-&gt;longUrl = $_GET[&apos;url&apos;]; //Shorten URL $shortUrl = $service-&gt;url-&gt;insert($url); $taskDone = true; }
  • GDG DevFest 2013 - PHP Web Apps on Google Cloud

    1. 1. PHP Web Apps on Google Cloud Bhavik Shah Software Architect. Technologist. Evangelist.
    2. 2. Introduction
    3. 3. PaaS Clouds with PHP!
    4. 4. Google App Engine Scalable, Reliable & Fast PaaS * Experimental PHP Support.
    5. 5. Why PHP? Built for Web Easy to Learn Most Requested <?php echo "Hello World!"; ?> PHP Frameworks Rapid Most popular 75% of Web is served by PHP (as per Google)
    6. 6. Symbiotic relation Google provides a great platform for PHP PHP brings a popular language to Google.
    7. 7. PHP on App Engine Image Courtesy: Google IO 2013
    8. 8. How to PHP?
    9. 9. Installation Python 2.7 Google App Engine SDK 1.8.4 PHP (Thread Safe) 5.4 Remember: Add each of it to your OS’s PATH variable. URLs http://www.python.org https://developers.google.com/appengine/ http://php.net/downloads.php Example installers (for Windows): GoogleAppEngine-1.8.3.msi and php-5.4.17-Win32-VC9-x86.zip
    10. 10. Sign up Google provides a great platform for PHP PHP provides a language to Google.
    11. 11. Create application Google provides a great platform for PHP PHP provides a language to Google.
    12. 12. Creating application locally - 1 app.yaml application: <your-app-id> version: 1 runtime: php api_version: 1 threadsafe: true handlers: - url: /assets   script: assets - url: /.*   script: index.php YAML
    13. 13. Creating application locally - 2 index.php <?php echo "Hello World!"; ?> PHP
    14. 14. Creating application locally - 3 php.ini ; php.ini google_app_engine.enable_functions = "php_sapi_name, php_uname, phpinfo" INI
    15. 15. Creating application locally - 4 phpinfo.php <?php echo phpinfo(); ?> PHP
    16. 16. Deploying Executing Application (Runs Locally) dev_appserver.py --php_executable_path= C:phpphp-cgi.exe <application id> Update source to Google App Engine appcfg.py update php-4-gae Access on Google App Engine http://<application id>.appspot.com/
    17. 17. Features
    18. 18. Cloud SQL MySQL 5.5 in Cloud Automatic Backups Automatic replication Geo-Located with App Resource Limit Maximum Request Size 16 MB Maximum Response Size 16 MB //PDO $db = new PDO('mysql:unix_socket=/cloudsql/hello-php:my-cloudsql-instance;charset=utf8', '<username>', '<password>' ); //mysql_connect $conn = mysql_connect(":/cloudsql/hello-php:my-cloudsql-instance", "<username>", "<password>"); //mysqli $sql = new mysqli(null, "<username>", "<password>", null, null, "/cloudsql/hello-php:my- cloudsql-instance"); PHP
    19. 19. Cloud Storage Built in Stream Wrappers allowing use of file api’s like file_get_contents(); $fp = fopen("gs://my_bucket/some_file.txt", "w"); fwrite($fp, "Hello"); fclose($fp); $options = [ "gs" => [ "Content-Type" => "text/plain" ]]; $ctx = stream_context_create($options); file_put_contents("gs://my_bucket/hello.txt", "Hello", 0, $ctx); PHP
    20. 20. Functions disabled by default Manual enabling possible via php.ini gc_collect_cycles(), gc_enable() and gc_disable() getmypid() getmyuid() getrusage() getmyinode() getmygid() get_current_user() libxml_disable_entity_loader()* parse_str() phpinfo() phpversion() PHP
    21. 21. Disabled Functions Permanently disabled disk_free_space() diskfreespace() escapeshellarg() and escapeshellcmd() exec() fsockopen() link() passthru() popen(), proc_close(), prog_get_status(), proc_nice(), proc_open() and proc_terminate() set_time_limit() shell_exec() show_source() symlink() system() tmpfile() tempnam() PHP
    22. 22. Limits on PHP Limit Amount request size 32 megabytes response size 32 megabytes request duration 60 seconds maximum total number of files (app files and static files) 10,000 total 1,000 per directory maximum size of an application file 32 megabytes maximum size of a static file 32 megabytes maximum total size of all application and static files first 1 gigabyte is free $0.13 per gigabyte per month after first 1 gigabyte All database requests must finish within the HTTP request timer, around 60 seconds. Offline requests like cron tasks have a time limit of 10 minutes. Backend requests to Google Cloud SQL have a time limit of 10 minutes.
    23. 23. Other Services Application Identity Logs Mail MemCache URL Fetch User Authentication Task Queues
    24. 24. Web App : URL Shortener Use Bootstrap with PHP Recommended: CodeIgnitor or Yii Source Code available at https://github.com/bhavik1st/php- 4-gae Web App on Google App Engine http://php-4-gae.appspot.com/ $client = new Google_Client(); $service = new Google_UrlshortenerService($client); $taskDone = false; if (isset($_GET['url'])) { // Start to make API requests. $url = new Google_Url(); $url->longUrl = $_GET['url']; //Shorten URL $shortUrl = $service->url->insert($url); $taskDone = true; } PHP
    25. 25. Demo
    26. 26. References & Other details developer.google.com venturebeat.com udemy.org Disclaimer: All images & logos used in the presentation are various trademarks of respective organizations. Other details Code : https://github.com/bhavik1st/php-4-gae Article: http://goo.gl/X7hbBI
    27. 27. Questions?
    28. 28. Thank you for your attention Bhavik Shah Twitter: bhavik1st Email: bhavik1st@gmail.com www.linkedin.com/in/bhavik1st

    ×