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

Scotch.io:
Prototype Quickly in Laravel with PHP’s Built-In Server and SQLite
May 06, 2016 @ 17:20:56

The Scotch.io site has a tutorial they've posted showing how to prototype a site quickly using Laravel and its built-in server/SQLite support.

If you are a seasoned Laravel developer, you know the usual project setup drill that involves creating a new project, a fresh database, and adding a virtual host entry to Apache.

If you are starting from scratch, the Apache and MySQL installation can take some time and slow things down for you. However, I will show you how you can jump start your Laravel development without Apache and MySQL.

The tutorial shows you how to use the internal PHP server to host the application, run a Laravel site inside it and integrate SQLite as the database. Each section comes with some example code and the commands/configuration you'll need to make the system work. They also take a "deep dive" into Larvel's serve command and how it bootstraps the Laravel instance for the PHP built-in server. The post ends with a look at switching back to MySQL and a comparison of SQLite vs MySQL (as well as using SQLite for production).

tagged: prototype laravel builtin server sqlite mysql tutorial

Link: https://scotch.io/tutorials/prototype-quickly-in-laravel-with-phps-built-in-server-and-sqlite

Lorna Mitchell:
OAuth2 with PHP's built in Streams Functions
Jan 07, 2016 @ 16:56:54

In a quick post to her site Lorna Mitchell reminds us that you can modify the options on the internal PHP streams (like for HTTP requests), more specifically to add a "Bearer" token value for OAuth2 integration.

For OAuth2, all I had to be able to do was to send an Authorization header with my web request from PHP. My second-favourite way of making API calls from PHP is to use PHP's stream handling, so I did that. It's not code you see very often but it's super-simple and it works on every PHP platform I've tried so far

She gives a few lines of code to show how to modify the options to add in the token value, basically using an array of options and a call to stream_context_create to create the context. This can then be used in future calls (like the file_get_contents she shows) to automagically send this information along with the request.

tagged: oauth2 http stream request builtin options bearer tutorial

Link: http://www.lornajane.net/posts/2016/oauth2-phps-built-streams-functions

Master Zend Framework:
Running the ZF2Skeleton with PHP’s Built-in Webserver
Apr 24, 2014 @ 14:25:07

The Master Zend Framework site has posted the first in their screencast series with a look at running the ZF2Skeleton with PHP’s built-in webserver.

In this screencast we’ll go through the creating an application from the ZF2Skeleton project on Github and getting it up and running, using PHP’s built-in web server. [It requires] PHP 5.4 or higher and Curl.

The screencast, coming in just over 3 minutes, briefly introduces you to the ZF2Skeleton project and shows you how to run it as a single process though PHP's own web server (useful for debugging). As a part of the installation, he also helps you get Composer installed as that's what Zend Framework 2 uses to install its packages correctly.

tagged: screencast tutorial webserver builtin zf2skeleton

Link: http://www.masterzendframework.com/casts/001

Gonzalo Ayuso:
How to run a Web Server from a PHP application
Nov 11, 2013 @ 17:53:06

Gonzalo Ayuso has put together a post showing how (by implementing the Reactor design pattern) he created a simple web server inside a PHP application. It combines a few Symfony2 components and the React library to build a simple server in a bit more programatic way.

Normally we deploy our PHP applications in a webserver (such as apache, nginx, …). I used to have one apache webserver in my personal computer to play with my applications, but from time to now I prefer to use PHP’s built-in webserver for my experiments. It’s really simple. [...] With PHP we cannot do it. Sure? That assertion isn’t really true. We can do it. I’ve just create one small library to do it in two different ways. First running the built-in web server and also running one React web server.

The idea is that all that would be needed is a stand-alone PHP script that could be run anywhere and start up its own web server, no other software required. He includes a simplified version of the example, showing how to make servers with both React and PHP's own server. He also includes an example of a basic Silex application that uses it as well as some benchmarks (with Apache ab) for each of the implementations and their request/response times on average for simple and Silex requests.

tagged: builtin webserver server example react silex

Link: http://gonzalo123.com/2013/11/11/how-to-run-a-web-server-from-a-php-application/

VG Tech:
Using PHP's Built-in Web Server in Behat Tests
Aug 19, 2013 @ 15:13:16

On the VG Tech blog there's a recent post showing you how you can use the built-in PHP web server to help with running your Behat (a behavior-driven development tool) tests.

Behat is a tool for running acceptance tests for your application. If your application is a web application you will need a web server to execute your tests. [...] Some weeks back I wrote a post showing you how to use PHP’s built in web server in PHPUnit. This post will show you how to do the same for Behat when running your acceptance tests.

His example (here on github) shows you how to set up Behat via Composer, run it and start in on your first test. In the test's "setUp" method, it calls out to the command line and starts up the built-in web server if it's not already running. It also checks to see if it can connect to the server to make sure it's accessible. Then, in the "tearDown" method, there's a call to kill off the PHP process based on the PID stored on startup.

tagged: builtin webserver bdd tests behat setup teardown

Link: http://tech.vg.no/2013/08/16/using-phps-built-in-web-server-in-behat-tests

VG Tech:
Using PHP's Built-in Web Server in Your Test Suites
Jul 22, 2013 @ 15:47:33

PHP introduced a handy built-in web server that makes it much simpler to test applications quickly and locally than having to have a full Apache+PHP install sitting on you machine. In this new post to the VG Tech blog, they take it one step further. They suggest that you can use it for testing too.

As of PHP-5.4.0 the CLI SAPI provides a built-in web server. The web server is designed for development purposes, and serves requests sequentially. This web server can come in really handy when the need for an httpd arises during (integration) tests. In this post I’ll use PHPUnit as the testing framework, and I’ll show you how to start the web server during the bootstrap process, and how to shut it down when the test suite is finished.

His example shows the creation of a basic phpunit.xml configuration file, but the bootstrap is a little different than some you've seen. With the help of a few constants and a command-line call to start the web server, he gets things up and running and ready for testing. A shutdown command is also included as a registered shutdown function to clean up after the testing is done.

tagged: webserver builtin phpunit unittest integration bootstrap tutorial

Link: http://tech.vg.no/2013/07/19/using-phps-built-in-web-server-in-your-test-suites

Chris Jones:
Using the PHP CLI Webserver to Identify and Test Memory Issues in PHP
Aug 15, 2012 @ 13:35:07

Chris Jones has a new post today showing how you can use PHP 5.4's built-in web server to help test for memory issues in your application (and the language).

Rasmus mentioned on IRC how he ran the [command line] tests: simply renaming the ".phpt" test files as ".php", and invoking them through the CLI webserver. The SKIPIF sections get executed, but that doesn't affect the desired outcome of testing multiple HTTP requests with different input scripts. [Here] are some quick shell scripts I put together to automate testing the OCI8 extension with valgrind.

He uses the OCI8 extension as an example, showing how to set up these scripts to enable the execution of the tests, fire up the web server and execute Valgrind to help monitor the memory of the execution.

tagged: builtin webserver cli test unittest phpt tutorial shell

Link:

Thomas Weinart:
Using The PHP 5.4 Webserver On Windows
Jul 31, 2012 @ 15:35:11

Thomas Weinert has posted a helpful hint for those developing their PHP applications in a Windows environment - how you can use the PHP 5.4 built-in webserver to test your applications.

PHP 5.4 has an built-in webserver. For local development it is not necessary to install Apache Httpd or another webserver anymore. You can just start an server from the command line. [...] To make things a little easier you can create a windows shortcut.

He shows what it looks like running in a console and steps you through the process of setting up the shortcut, giving you the flexibility to contril things like window size and buffer size.

tagged: winodws builtin webserver shortcut commandline

Link:

PHPMaster.com:
Taking Advantage of PHP's Built-in Server
Mar 08, 2012 @ 14:17:45

On PHPMaster.com today there's a new tutorial for those on the bleeding edge of PHP using the latest released version (5.4) and a feature that comes with it - using the built-in webserver that comes bundled for testing purposes.

One of the cooler features of the new PHP 5.4 release is a built-in web server designed specifically for development and testing. Now you can write and test your code without having to have a full-fledged LAMP configuration - just launch a the built-in server from the command line, test your code, and then shut it down when you're finished. [...] In this article I'll explain some basic uses of the new built-in server and show you how to build a portable personal development server useful for quickly testing your applications

He starts with a look at how to start up the web server (a simple command line switch and host/port definition) and the resulting default phpinfo page it displays. Other options include the ability to specify a document root for your server and create a sort of "front controller" for it to route requests. They show how to create a simple application based on this that can dynamically load in the index file, a router and pass the request off to the correct file. Their example includes some "niceties" too like logging, "hosts allowed" and checks for requesting directories.

You can find their full code for this example over on github.

tagged: builtin server recent router feature test custom tutorial

Link:

Lorna Mitchell's Blog:
PHP 5.4 Built In Webserver
Jan 30, 2012 @ 17:35:09

Lorna Mitchell has posted a quick tutorial about a feature of the upcoming PHP 5.4 release, the built-in web server, and some tips on doing things like routing requests and changing the hostname.

One of the big features arriving with PHP 5.4 is the addition of a built-in basic webserver for use in development environments. Quite a few of the other scripting languages have something like this so I'm very pleased to see it in PHP. Using a server like this makes it easy to quickly try out some scripts without needing to configure apache or really do anything much! I had to look up a few things to get started, so I thought I'd write them down for posterity.

She includes instructions on how to get the server up and running from the command line, updating the location of the document root with a command line option and using a simple "routing.php" script to act as a front controller. Changing the hostname is as simple as changing "localhost" to something else when starting the server.

tagged: webserver builtin configure tutorial server

Link:


Trending Topics: