News Feed
Sections




News Archive
feed this:

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

Symfony Blog:
PSR-7 Support in Symfony is Here
June 01, 2015 @ 12:19:15

The Symfony project has officially announced PSR-7 support in the latest version of the framework. PSR-7 is a recently approved standard by the PHP-FIG to make a more structured HTTP request and response structure (to aid in interoperability).

Less than 2 weeks ago, the PHP community roundly accepted PSR-7, giving PHP a common set of HTTP Message Interfaces. This has huge potential for interoperability and standardization across all of PHP. This is especially true for middleware: functions that hook into the request-response process. In the future, a middleware written around these new interfaces could be used in any framework. [...] Today, a huge number of projects use Symfony's Request and Response classes (via the HttpFoundation component), including Laravel, Drupal 8 and StackPHP.

[...] For that reason, we're thrilled to announce the 0.1 release of the PSR HTTP Message Bridge: a library that can convert Symfony Request and Response objects to PSR-7 compatible objects and back. This means that once there are middleware written for PSR-7, applications using HttpFoundation will be compatible.

The bridge makes it simpler to swap out the HTTP layer by converting the HTTP objects into something other frameworks can use (or so others can be used by Symfony). They provide some examples of how to put it to use, converting objects both to and from the standard Symfony HttpFoundation versions. There's also a quick note about the RequestInterface and ResponseInterface structure that allows you to bridge your own gaps between the PSR-7 friendly components and Symfony.

0 comments voice your opinion now!
psr7 support httpfoundation request response http bridge phpfig

Link: http://symfony.com/blog/psr-7-support-in-symfony-is-here

Web Development Blog:
Add a MailChimp subscribe feature to your contact form
May 05, 2015 @ 12:14:13

The Web Development Blog has a tutorial posted showing how to add a Mailchimp "subscribe" feature to your current contact forms. They make use of the MailChimp API wrapper library to make the calls back to the service and subscribe the user at their request.

MailChimp is a great email marketing service provider with an easy to use control panel and features like: campaign management (RSS-driven, A/B Split, Plain-text and regular), statistics, auto-responder and a complete set of list management tools. They offer different ways to place a subscriber form on your website or blog. If you to like add the MailChimp subscribe feature to your existing contact form you need to add some custom code.

They start with a few things you'll need to do to prepare for the connection including the setup of an API key to make the request. He provides a simple "Contact Us" form for reference and the code needed on submit to validate the input and make the subscription call to the API with the email the user provided. He also includes a bit of response handling.

0 comments voice your opinion now!
mailchimp tutorial subscribe contactus form api request

Link: http://www.web-development-blog.com/archives/mailchimp-subscribe-contact-form/

ClanCats Station:
Writing a webserver in pure PHP - Tutorial
March 26, 2015 @ 11:27:42

On the Clancats.com blog there's a recent post showing how to create a web server in pure PHP, an interesting experiment but definitely not recommended for any kind of higher load situation.

Well, this is pretty useless, but it is possible. But again its pretty.. uesless. This tutorial will hopefully help you to better understand how a simple webserver could work and that it's no problem writing one in PHP. But again using this in production would be trying to eat a soup with a fork. So just, .... just don't. Let me shortly explain why this is not a that good idea.

PHP is a scripting language that simply is not really designed for such tasks. A webserver is a long running process which PHP is not made for. Also PHP does not natively support threading ( pthreads ), which will make developing a good performing webserver a really hard task.

He walks you through all the code needed to create the web server (also available on GitHub) by making:

  • A "server" that does the listening for incoming and sends outgoing requests
  • A request object that parses the incoming request and makes header and body content available
  • A response object that allows for the setting of response codes, body content and headers
  • Exception handling for problems encountered during the request/response process

The full code is provided during the process along with explanations of what each part does. There's also a basic introduction to what a typical web server is and how the process of request/response usually flows.

0 comments voice your opinion now!
webserver tutorial version request response server

Link: http://station.clancats.com/writing-a-webserver-in-pure-php

Evert Pot:
PSR-7 is imminent, and here's my issues with it.
March 04, 2015 @ 09:26:37

Evert Pot has written up a new post today with some of his thoughts about what's wrong with the PSR-7 proposal in the PHP-FIG. PSR-7 relates to a standardized interface for HTTP request and response handling.

PSR-7 is pretty close to completion. PSR-7 is a new 'PHP standard recommendation', put out by the PHP-FIG group, of which I'm a member of. [...] PSR-7 gets a lot of things right, and is very close to nailing the abstract data model behind HTTP, better than many other implementations in many programming languages.

But it's not perfect. I've been pretty vocal about a few issues I have with the approach. Most of this has fallen on deaf ears. I accept that I might be a minority in feeling these are problems, but I feel compelled to share my issues here anyway. Perhaps as a last attempt to sollicit change, or maybe just to get it off my chest.

He breaks up his thoughts into a few different categories, each with a summary and sometimes some code to help make his point a bit more clear. He talks about immutability, how objects will be immutable and shows an example of change in how Silex would have to function to follow the standard (with before/after). He then goes on to talk about the "issue with streams" and how the current proposal could allow for changing of the incoming request into a new one with new headers...not immutable. He ends the post talking about PSR-7's stance on buffering responses and how, even if his project doesn't adopt the PSR in the strictest sense, they may still take some inspiration from it.

0 comments voice your opinion now!
psr7 issues opinion phpfig http standard request response

Link: http://evertpot.com/psr-7-issues/

Matthew Weier O'Phinney:
PSR-7 By Example
January 29, 2015 @ 09:13:20

As a part of his involvement in the PHP-FIG standards group, Matthew Weier O'Phinney has been contributing to the PSR-7 proposal. This proposal defines a standardized structure for HTTP message handling. In his latest post he gets into a bit more detail on what this means for the PHP developer and how it might be implemented.

PSR-7 is shaping up nicely. I pushed some updates earlier this week, and we tagged 0.6.0 of the http-message package last week for implementors and potential users to start coding against. I'm still hearing some grumbles both of "simplify!" and "not far enough!" so I'm writing this posts to demonstrate usage of the currently published interfaces, and to illustrate both the ease of use and the completeness and robustness they offer.

He starts with a base definition of what the proposal, well, proposes around HTTP messaging, both the incoming and outgoing. He describes the basic structure of an HTTP message and what each part represents. He talks about message headers, bodies and how the current library could return that content. He then looks at requests vs responses, server-side requests and some various uses cases and more practical examples:

  • HTTP Clients
  • Middleware
  • Frameworks

With the PSR-7 standard in place, all of these different tools could have interchangeable interfaces for HTTP request/responses, easily swappable with any other implementation.

0 comments voice your opinion now!
psr7 http message request response summary tool framework middleware client

Link: https://mwop.net/blog/2015-01-26-psr-7-by-example.html

Michael Dowling:
Guzzle-Ring and Future Responses
September 30, 2014 @ 09:36:32

Michael Dowling has a new post to his site today talking about the work that's being done on the upcoming release of the Guzzle HTTP client. In the post he talks about a major change in how it allows for asynchronous requests and the work on Guzzle-Ring to make it happen.

Guzzle 4 has been out for a little over six months. It has proven to be leaps and bounds better than Guzzle 3, and I've been very happy with the design so far. However, after the release of Guzzle 4, I've received feedback from numerous members of the PHP community that can be boiled down to "Guzzle needs async support." While Guzzle has always had the ability to send requests concurrently using a pool of requests, there was not a way to send asynchronous requests.

After a couple months of work and borrowing concepts from Clojure, I've created Guzzle-Ring, an extremely simple adapter and middleware library for PHP (not just Guzzle) that can power both clients and servers for both synchronous and asynchronous requests.

The Guzzle-Ring reduces the need for the previous complexity of creating multiple adapters, which ended up with the adapters knowing too much about the request itself. He introduces the Guzzle-Ring system that will be included in Guzzle v5, heavily influenced by Clojure. The adapter makes the request as simple as passing in an array and makes use of "futures" to handle the request/response cycle. He also talks some about creating middleware piece that helps integrate it into your application, wrapping functionality inside of another method. He illustrates all of this with code examples and includes others such as fetching of future responses, sending requests concurrently and the Guzzle-Ring server adapters.

0 comments voice your opinion now!
guzzle guzzlering http client asynchronous request futures guzzle5 clojure

Link: http://mtdowling.com/blog/2014/09/28/guzzle-ring/

Qandidate.com Blog:
Handling AngularJS POST requests in Symfony
August 14, 2014 @ 11:09:13

The Qandidate.com blog has a quick new post today showing how to handle AngularJS requests with a Symfony framework based backend application. They automate the process of decoding the JSON from the Angular frontend to make it immediately usable to the framework backend.

At Qandidate.com we started using AngularJS last year and I have to say it was love at first sight! Two-way databinding, testability, dependency injection, server communication...awesome! Did I say server communication? We use Symfony 2 (which is awesome too) for our back end API's. Unfortunately AngularJS and Symfony do not speak the same language out-of-the-box. In this post I will show you how we automatically decode JSON requests so we can use it with Symfony's Request object using our symfony-json-request-transformer library (or class actually).

They start with a simple JSON example and the action to handle it (the "postAction") and show the manual json_decode method. Instead of having to do this in each controller action, they define the Request transformer handler. This handler takes the incoming request and allows for modifications to various aspects of the request, including transforming the data. They've posted a full example here that includes the full stack, not just the transformer itself (to show the full flow of the request).

0 comments voice your opinion now!
angularjs request symfony2 transform json request

Link: http://labs.qandidate.com/blog/2014/08/13/handling-angularjs-post-requests-in-symfony/

CodeSamplez.com:
PHP HTTP Request With Guzzle
June 12, 2014 @ 11:55:07

If you're making HTTP requests in your applications and you haven't looked into using Guzzle, you're missing out on one of the most powerful, flexible HTTP tools out there. In this new post to the CodeSamplez.com site they introduce you to the tool and show you how to make a few sample requests.

If you are consuming some kind of API with complex PHP HTTP requests which doesn't provide a clean wrapper library, I can feel the nightmare you might be having. Same could be happen if you are yourself writing such kind of API wrapper as well. Here, I will try to introduce you with guzzle library and getting a quick start. This article is targeted for complete beginners, so if you are already somewhat experienced, you either might skip this or review it and help me improve it to fit as a robust getting started tutorial.

He covers some of the things that can be done with Guzzle (including connecting to APIs and scraping site data) and briefly mentions some alternatives to the tool. Code is included to make a first request: a simple call to the GitHub API that fetches URL information for other resources. He also includes an example of making a POST request and using the OAuth module that comes with Guzzle, making those requests easier.

0 comments voice your opinion now!
http request guzzle introduction tutorial

Link: http://codesamplez.com/programming/php-http-request-guzzle

Chris Hartjes:
The Power of the BrowserProxyMob
November 19, 2013 @ 10:49:38

In this new post to his site Chris Hartjes shares a tool he's found to help with automated front-end testing for web applications - BrowserMobProxy

At work I have been involved with an effort to put some automated front-end testing in place. The combination of Behat, Mink running tests using PhantomJS is a good one for this. Open source, easy to configure, handles JavaScript-heavy pages reasonably well. There was just one wrinkle in our plans: our use of local host files. [...] So clearly what was needed [to solve a hosts file switching issue] was a proxy. After doing a little bit of digging around I found a solution: BrowserMobProxy.

He briefly introduces the tool and helps you get it installed (as well as the library you'll need to interface with the proxy). His library hooks into a running PhantomJS instance and the BrowserMobProxy, generates the right hosts file (not included) and continues on with the tests.

0 comments voice your opinion now!
browserproxymob proxy http request phantonjs unittest behat mink

Link: http://www.littlehart.net/atthekeyboard/2013/11/18/the-power-of-the-browserproxymob/

Mohammad Emran Hasan:
Concurrent HTTP requests in PHP using pecl_http
October 07, 2013 @ 10:42:09

Mohammad Emran Hasan has posted a quick example of using the pecl_http extension to make concurrent HTTP requests.

The pecl_http extension has a little gem that can be handy at times - HttpRequestPool. Using this, you can send concurrent HTTP requests and can gain efficiency in fetching non-related data at once. For example, from an external source if your application needs to retrieve an user's profile, their order history and current balance, you can send parallel requests to the API and get everything together.

His code shows three example connections to a made up URL on three different endpoints. With the HttpRequestPool functionality, all three can be requested at once and tracked to extract the response body.

0 comments voice your opinion now!
concurrent http request httprequestpool pecl peclhttp extension

Link: http://emranhasan.com/2013/09/concurrent-requests-in-php-using-pecl_http/


Community Events

Don't see your event here?
Let us know!


laravel application list introduction symfony framework interview php7 api yii2 composer testing series project example community podcast opinion language part2

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework