Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Serverless PHP on AWS Lambda
Jan 03, 2019 @ 16:36:31

Rob Allen has a tutorial posted to his site showing how you can run PHP using the serverless lambda functionality that Amazon Web Services provides.

There are other serverless providers, and AWS Lambda is the market leader, but until recently PHP support could most charitably described as cumbersome. That all changed at the end of 2018 with Lambda’s new runtime API and support for layers.

Let’s look at the practicalities of serverless PHP on Lambda with Serverless Framework.

If you'd like to skip to the "good parts" you can check out this repository of the resulting code. Otherwise, he provides a complete walkthrough of the setup and code required to get the lambda up and running:

  • compiling the PHP binary on an EC2 instance (so it will be compatible)
  • creating a bootstrap file for handling requests
  • setting up the yml configuration for the Serverless framework
  • writing the "hello world" function
  • deploying to the lambda system

Finally he shows how to call the "hello" function using the command line and the response you should receive.

tagged: aws lambda tutorial helloworld serverless framework

Link: https://akrabat.com/serverless-php-on-aws-lambda/

Rob Allen:
Using Serverless Framework with OpenWhisk PHP
May 31, 2018 @ 15:43:01

In a new post to his site Rob Allen provides the steps you'll need to follow to use the Serverless Framework toolkit with OpenWisk to host PHP-based applications.

Serverless Framework is a toolkit to help you mange and deploy a serverless application. (Personally, I'm not a fan of the name as the word "Serverless" already has a meaning in the same space!) It's a useful tool and supports all the major providers, though AWS Lambda seems to be first-among-equals. The OpenWhisk plugin for Serverless is maintained by the rather excellent James Thomas, so if you have any questions, ping him!

As I build more complex PHP based OpenWhisk applications, I thought I'd explore how Serverless makes this easier.

He starts with helping you get the Serverless framework and the related OpenWisk plugin installed. He then helps you create a project, modify the configuration for a simple "Hello world" kind of script and create the PHP script to act as an endpoint. With the setup complete, he includes the steps to deploy and run the project, invoking the action and enabling it (as a Web Action) to make it reachable via the web.

tagged: serverless framework tutorial openwisk helloworld setup configure deploy

Link: https://akrabat.com/using-serverless-framework-with-openwhisk-php/

Alex Bowers:
Writing a Hello World PHP 7 Extension
Aug 25, 2016 @ 17:25:47

In a recent post to his site Alex Bowers shows you the steps involved in creating a "Hello World" PHP 7 extension with some basic output functionality - basically just echoing out a message.

He jumps right into the code and shows you how to:

  • set up the directory and initial files for the extension
  • write the test case first (a simple PHP file checking if it's loaded and can be used)
  • updating the config.m4 to allow for enabling the extension
  • the code for src/hello.h to define the function

The final piece is the code in the src/hello.c - the C code to define some structure for the PHP interpreter to understand and be able to execute the PHP_FUNCTION(hello_world). Finally he shows how to make the extension to install it, add it to your php.ini file as a shared module and re-run the test.

tagged: helloworld extension tutorial example simple php7

Link: https://zando.io/writing-a-hello-world-php-7-extension/

Zaengle Blog:
Exploring Laravel's Custom Blade Directives
Mar 14, 2016 @ 18:38:30

On the Zaengle blog there's a post spotlighting the custom Blade directive functionality that comes with using the Blade templating engine of the Laravel framework. These allow the definition of custom functionality available directly from the templating layer.

Earlier today, I was working on coding up a design that displays a varying number of cards - each with a unique title and description… think Masonry/Pinterest-esque. I’ve been using Model Factories to stub out a bunch of cards, all with different content. Once I’d hooked up the dummy data to the card templates, I realized that the design didn’t work as well with titles that had more than 20 or so characters.

A common solution to this would be to use CSS to break the line and automatically add an ellipsis. [...] However, this wouldn’t work well in my situation because the design allows titles to be two lines long. Another solution would be to chop off the title at a given length and add an ellipsis using a php snippet. [...] However, adding this much PHP to my Blade templates would have really mucked up my otherwise-clean templates. So I decided to drop this functionality into a custom Blade directive that I could reuse where necessary.

He shows how to define the custom Blade directive in the AppServiceProvider class (autoloaded with every request) for a simple "Hello World" example. He also shows how to use this in the template code, making a simple call to its matching helloWorld tag. He then implements his custom truncate handling, returning some simple PHP code that automatically reduces the content down to a given length and echoes out the result.

tagged: laravel custom blade directive tutorial helloworld truncate

Link: http://zaengle.com/blog/exploring-laravels-custom-blade-directives

Jared McFarland:
Creating a PHP extension in Rust
Apr 06, 2015 @ 14:22:02

Jared McFarland has a recent post to his site showing how to make a PHP extension in Rust, a more recent programming language that seeks to "run fast, prevent almost all crashes and eliminate data races".

Last October I had a discussion with one of my coworkers at Etsy about how writing extensions to interpreted languages like PHP, Ruby or Python should be a lot easier than it is now. We talked a bit about how one of the barriers to successfully writing an extension is they’re generally written in C, and it’s hard to gain confidence in C code if you’re not an expert at the language.

Ever since then I’ve toyed with the idea of writing one in Rust, and for the past few days have been playing around with it. I finally got it to work this morning.

He starts by static his goal, to make a PHP extension with Rust that was compiled into a library along with some C headers. He talks about his use of the Rust Foreign Function Interface to make a "hello world" script and the code to call it from C, complete with header code examples and the result of it being called. He then gets into the PHP integration, showing you the code you'll need for the extension and compiling it into a module and moving it into the extension directory. He also includes some "useless micro-benchmarks" so you can see how things perform, comparing his function to base PHP when calculating the Fibonacci sequence algorithm.

tagged: extension rust programming language helloworld tutorial

Link: http://jaredonline.svbtle.com/creating-a-php-extension-in-rust

Lorna Mitchell:
First Phing Plugin
Mar 25, 2013 @ 15:49:23

In the latest post to her site, Lorna Mitchell walks you through the creation of a first Phing plugin, an extension to the popular PHP-based build tool.

I'm a huge fan of Phing and use it regularly for build and deployment tasks. Often, I'll ask about a plugin that I wish existed, and get a very courteous "patches welcome" from the nice people in the #phing channel on freenode. This has happened a few times, so I thought I should probably look at how to make a new phing plugin, this article shows you how to make the simplest thing I could think of: a simple "hello world" plugin.

She points you to the location to grab the latest version of the tool (the github repository) and how to define a configuration file for your test runs. Then she includes the sample code showing how to create the "HelloTask" plugin. It takes an input value of "name" and displays a greeting when executed. She shows the syntax for defining this in the XML build file and the sample result when executed.

tagged: phing plugin install build configuration xml helloworld task

Link:

Reddit.com:
Fastest MVC PHP Framework Benchmark
Aug 21, 2012 @ 17:12:48

Over on Reddit.com there's a flamewar...er discussion happening about this set of benchmarks (from 2011) showing things like response time, system load average and a function execution map for several popular frameworks.

In the Reddit comments most people share the similar ideas about the results:

  • "I don't put much stock in hello world bench marks for MVCs. If you just need "Hello world" then write it in html."
  • "Asking which framework is the fastest is almost irrelevant in most cases. I always dislike benchmarks like this because the actual situation is so much more complicated than a handful of benchmarks can show."
  • "Any decent framework can output a simple content page from cache, it should not even have to call any router or controller. That's why simple content benchmarks are useless."
  • "Who cares? The speed of a language or framework does not translate over to the speed of your website. What matters is your architecture."

If you're looking for benchmarks that are more useful than these, I'd suggest checking out (and maybe contributing to) the ones Paul Jones has created over on Github.

tagged: mvc framework benchmark helloworld opinion

Link:

PHPMaster.com:
Using Phing
Jan 05, 2012 @ 16:41:40

On PHPMaster.com today there's a new tutorial posted about using the Phing build tool to automate a process, usually a build for a website launch. In his example, he shows a simple "Hello World" example and how to work with multiple targets in the same build file.

Phing is a PHP project build tool based on Apache Ant. A build system helps you to perform a group of actions using a single command. [...] Phing helps overcome [human error] issues by automating tasks like running unit tests, applying database changes, deploying application code, etc. In this article I’ll show you some of the basics of working with Phing.

He includes the commands you'll need to install Phing (if it's not already) via the PEAR installer and a basic "build.xml" file. He explains the parts of the file - tags for "project", "target" "echo" and "property - and includes a more complex build example with multiple targets (and how to call one specifically from the command line).

tagged: phing build tool tutorial multiple target helloworld

Link:

Dave Marshall's Blog:
Traits in PHP 5.4 - HelloWorld with Logging Trait
Aug 08, 2011 @ 15:24:36

Dave Marshall is already looking ahead to the next major release of PHP, version 5.4, and one of the features it will include - traits. In this new post to his blog, he introduces a "logging trait" he's come up with to make logging simpler in your (Zend Framework) application.

One of the 'traits' I find myself constantly adding to library files is optional logging of it’s behaviour. The library class has it’s own log method, that checks to see if the instance has had a logger injected and if so, logs the message. I see this as a perfect candidate for becoming a reusable trait, as I tend to have the same code copy/pasted throughout my library classes. The problem is, according to the rfc, traits aren’t supposed to have state/properties, which makes it difficult to have a DI setter method in a trait.

He includes the code for his trait example (noting that it may or may not end up working correctly in the 5.4 final release) that sets a logger on a sample class and logs a few values out to the console. It's a simple example, but it shows you one of the most useful things about traits - the "drop in resuability" nature they allow in your libraries and classes.

tagged: traits example logging zendframework helloworld

Link:

Josh Holmes' Blog:
Hello World Azure in PHP
Feb 11, 2010 @ 19:25:56

For anyone wanting to take those first steps into running PHP applications on an Azure platform, you should check out a new post from Josh Holmes. He describes the process of getting it working from a command-line approach.

I thought we could kick it up a notch [from his previous post] and get PHP running in Azure leveraging the command line tools. The primary thing that we need to do is to copy the PHP bits up with the rest of your deployment and configure the FastCGI handler to know where the PHP interpreter can be found.

Once you get PHP installed testing it out is just a matter of getting his test page in the right directory, updating one of the configuration files (web.roleconfig), creating the Config/Definition files and packaging it all up with cspack. All of the contents for the sample configuration files and a screenshot of the fnal output are included.

tagged: helloworld azure microsoft tutorial

Link:


Trending Topics: