SlideShare a Scribd company logo
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 Web is served by PHP
(as per Google)
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 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
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: true
handlers:
- url: /assets
  script: assets
- url: /.*
  script: index.php
YAML
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"
INI
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>
Update source to Google App Engine
appcfg.py update php-4-gae
Access on Google App Engine
http://<application id>.appspot.com/
Features
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
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
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
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
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.
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/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
Demo
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
Questions?
Thank you for your attention
Bhavik Shah
Twitter: bhavik1st
Email: bhavik1st@gmail.com
www.linkedin.com/in/bhavik1st

More Related Content

PDF
わかった気になるgitit-0.8
PDF
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
PPTX
Dc kyiv2010 jun_08
PPTX
Sessions and cookies in php
PDF
MeshU Thin & Rack
PDF
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
PDF
Puppet Camp 2012
PDF
Prototyping in the cloud
わかった気になるgitit-0.8
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
Dc kyiv2010 jun_08
Sessions and cookies in php
MeshU Thin & Rack
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Puppet Camp 2012
Prototyping in the cloud

What's hot (19)

KEY
GettingStartedWithPHP
PPT
Drupal Performance - SerBenfiquista.com Case Study
PDF
WP migrations
PDF
Challenges of container configuration
PDF
autopkgtest lightning talk
PDF
Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...
PDF
Scaling up development of a modular code base
PPT
Heavy Web Optimization: Backend
PDF
SECCOM 2017 - Conan.io o gerente de pacote para C e C++
PPTX
2012 coscup - Build your PHP application on Heroku
PDF
Asynchronous PHP and Real-time Messaging
PDF
Perlmania_Study - CPAN
PDF
Configuration surgery with Augeas (OggCamp 12)
TXT
Simple php backdoor_by_dk
PDF
Debugging: Rules & Tools
PDF
HTML5 tutorial: canvas, offfline & sockets
PDF
livedoor blogのsorryサーバの話 #study2study
PDF
Mac OS X Lion で作る WordPress local 環境
PDF
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
GettingStartedWithPHP
Drupal Performance - SerBenfiquista.com Case Study
WP migrations
Challenges of container configuration
autopkgtest lightning talk
Puppet Camp Phoenix 2015: Managing Files via Puppet: Let Me Count The Ways (B...
Scaling up development of a modular code base
Heavy Web Optimization: Backend
SECCOM 2017 - Conan.io o gerente de pacote para C e C++
2012 coscup - Build your PHP application on Heroku
Asynchronous PHP and Real-time Messaging
Perlmania_Study - CPAN
Configuration surgery with Augeas (OggCamp 12)
Simple php backdoor_by_dk
Debugging: Rules & Tools
HTML5 tutorial: canvas, offfline & sockets
livedoor blogのsorryサーバの話 #study2study
Mac OS X Lion で作る WordPress local 環境
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
Ad

Similar to GDG DevFest 2013 - PHP Web Apps on Google Cloud (20)

PPT
3. build your own php extension ai ti aptech
PPT
07 build your-own_php_extension
PPT
Build your own PHP extension
PPT
Php Tutorial
PDF
Living With Legacy Code
PPTX
PHP Hypertext Preprocessor
PPTX
Google App Engine for PHP
PDF
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
PDF
The new features of PHP 7
PDF
Deploy a PHP App on Google App Engine
PDF
PHP Backdoor: The rise of the vuln
PDF
PSR-7 and PSR-15, why can't you ignore them
PPTX
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
PDF
PPT
Hacking with hhvm
ODP
PHP: The easiest language to learn.
PPTX
Day1
PDF
Diving into HHVM Extensions (Brno PHP Conference 2015)
PPT
build your own php extension
3. build your own php extension ai ti aptech
07 build your-own_php_extension
Build your own PHP extension
Php Tutorial
Living With Legacy Code
PHP Hypertext Preprocessor
Google App Engine for PHP
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7
Deploy a PHP App on Google App Engine
PHP Backdoor: The rise of the vuln
PSR-7 and PSR-15, why can't you ignore them
Diving into HHVM Extensions (PHPNW Conference 2015)
Hacking with hhvm
PHP: The easiest language to learn.
Day1
Diving into HHVM Extensions (Brno PHP Conference 2015)
build your own php extension
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

GDG DevFest 2013 - PHP Web Apps on Google Cloud

  • 1. PHP Web Apps on Google Cloud Bhavik Shah Software Architect. Technologist. Evangelist.
  • 4. Google App Engine Scalable, Reliable & Fast PaaS * Experimental PHP Support.
  • 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. Symbiotic relation Google provides a great platform for PHP PHP brings a popular language to Google.
  • 7. PHP on App Engine Image Courtesy: Google IO 2013
  • 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. Sign up Google provides a great platform for PHP PHP provides a language to Google.
  • 11. Create application Google provides a great platform for PHP PHP provides a language to Google.
  • 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. Creating application locally - 2 index.php <?php echo "Hello World!"; ?> PHP
  • 14. Creating application locally - 3 php.ini ; php.ini google_app_engine.enable_functions = "php_sapi_name, php_uname, phpinfo" INI
  • 15. Creating application locally - 4 phpinfo.php <?php echo phpinfo(); ?> PHP
  • 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/
  • 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. 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. 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. 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. 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. Other Services Application Identity Logs Mail MemCache URL Fetch User Authentication Task Queues
  • 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. Demo
  • 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
  • 28. Thank you for your attention Bhavik Shah Twitter: bhavik1st Email: bhavik1st@gmail.com www.linkedin.com/in/bhavik1st

Editor's Notes

  • #2: Image Courtesy: Wikimedia, http://gdg-generator.appspot.com/, GDG
  • #5: 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.
  • #6: 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 , 
  • #7: Despite critic of PHP about language inconsistency, scalability, performance.
  • #8: Multiple data centers Memcache optimizes Mysql library ..
  • #10: 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.
  • #17: 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.
  • #19: 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;);
  • #23: 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.
  • #25: $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; }