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

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/

PHPMaster.com:
Using cURL for Remote Requests
August 08, 2013 @ 09:09:13

PHPMaster.com has posted a tutorial showing you how to use the cURL functionality that can be built into PHP. Note that not all PHP installations will have this extension installed, but most will these days. You can find out by making a phpinfo page.

If you're a Linux user then you've probably used cURL. It's a powerful tool used from posting mails to downloading the latest My Little Pony subtitles. In this article I'll explain how to use the cURL extension in PHP. The extension offers us the functionality as the console utility in the comfortable world of PHP. I'll discuss sending GET and POST requests, handling login cookies, and FTP functionality.

He walks thorough the basic flow of a request and how to set options on the cURL handle to modify its behavior. Several more "real world" examples are also included:

  • Retrieve a Web Page
  • Log in to a Website (via POST data, not HTTP Auth)
  • Working with FTP
  • Sending Multiple Requests

That last one changes things up a bit and uses the curl_multi_init function to create the connection and allow for the multiple request streams to happen.

0 comments voice your opinion now!
curl remote request tutorial login ftp multiple

Link: http://phpmaster.com/using-curl-for-remote-requests

Paul Reinheimer:
PHP and Async requests with file based sessions
July 24, 2013 @ 09:52:43

Paul Reinheimer had a problem - when he was making asynchronous requests back to his server from his frontend (Ajax) there was a slowness he noticed when more than one connection was fired off. In this new post to his site he traces through how he found the answer and what he did to fix it.

Digging a little deeper into the queries being executed, I was expecting return times in the order of 200ms, not the several seconds I was seeing. Installing XHGui only furthered my confusion: session_start() was the culprit with incredibly high run times.

He thought first about the number of session files (stored locally) being too large and causing issues, but that turned out to be a false lead. Instead, the issue was something PHP does by default...and does correctly. When PHP executes, it locks the session file, preventing another process from writing to it. This caused the delay he saw until it was unlocked. His solution? Use session_write_close immediately after writing information to unlock the session for further use.

0 comments voice your opinion now!
asynchronous session lock delay filebased request

Link: http://blog.preinheimer.com/index.php?/archives/416-PHP-and-Async-requests-with-file-based-sessions.html

VG Tech:
PHP Perform Requests in Parallel
July 23, 2013 @ 10:58:11

On the VG Tech blog today Espen Hovlandsdal has a quick tutorial showing you how to run cURL requests in parallel using the curl_multi_* functions included in PHP.

Ever had to request multiple HTTP-resources in your web application? Often, you need data from one request to be able to request the second - in this case there is little you can do but wait for the first to return. However, if the requests are not dependent on each other, you can use a pretty cool trick: curl_multi_*.

He first gives a single-threat example, showing how you might loop through a set of URLs to make the request and get the response. As an alternative, he shows the "multi" version right after. It sets up a "queue" of handles to different requests and executes them until they stop returning data. He also includes an example using the Guzzle HTTP client that makes it look cleaner and wraps some additional functionality around the requests.

0 comments voice your opinion now!
request parallel curl multiple tutorial guzzle

Link: http://tech.vg.no/2013/07/23/php-perform-requests-in-parallel

NetTuts.com:
HTTP The Protocol Every Web Developer Must Know - Part 1
April 09, 2013 @ 10:56:28

On NetTuts.com there's a new tutorial about what they think is the one thing every web developer should understand - the HTTP protocol and how its used in web-based communications.

HTTP stands for Hypertext Transfer Protocol. It's a stateless, application-layer protocol for communicating between distributed systems, and is the foundation of the modern web. As a web developer, we all must have a strong understanding of this protocol. Let's review this powerful protocol through the lens of a web developer. We'll tackle the topic in two parts. In this first entry, we'll cover the basics and outline the various request and response headers.

They cover some of the basics of the protocol first including its statelessness, the concept of URLs and the HTTP "verbs" (like GET, POST and DELETE). They also briefly cover the HTTP response codes (ex. 200, 304) and the flow of the request and response to and from the web server. They also look at some of the basic HTTP headers and the actual low-level text formats of the requests/responses.

There's a section at the end of the post that links you to a few tools that you can use to view the HTTP messaging happening in your requests, some of which you might already have. They also briefly cover the use of HTTP in a few libraries - ExpressJS, Ruby on Rails and jQuery's Ajax handling.

0 comments voice your opinion now!
http protocol series basics headers statuscode verb request response

Link: http://net.tutsplus.com/tutorials/tools-and-tips/http-the-protocol-every-web-developer-must-know-part-1/

Igor Wiedler:
Stateless Services
April 04, 2013 @ 10:41:50

Igor Wiedler has a recent post to his site about creating stateless services, specifically in the context of using a dependency injection container to manage the objects your application uses.

As more frameworks and libraries, particularly in the PHP world, move towards adopting the Dependency Injection pattern they are all faced with the problem of bootstrapping their application and constructing the object graph. In many cases this is solved by a Dependency Injection Container (DIC). Such a container manages the creation of all the things. The things it manages are services. Or are they?

He notes that, according to some of the principles of domain-driven design, "services" should be stateless - the results of calls to the service shouldn't alter it, it should only depend on the values passed in. He goes on to put this into the context of a DIC and gives an example of the "request service" (and how it violates the DDD principles of statelessness). He talks some about scopes (dependencies) and mutable services. He talks about methods to get around these issues with the "request" instance, ultimately coming to the conclusion that event listeners might be the way to go.

0 comments voice your opinion now!
stateless services dependency injection event listener request

Link: https://igor.io/2013/03/31/stateless-services.html

Hari KT:
Aura.Http Request and Response
February 18, 2013 @ 11:49:58

On his blog today Hari KT has an Aura Framework-related post about one of its components, the Aura.Http component, and its handling of HTTP requests and responses.

The Aura.Http package provide you the tool to build and send request and response. [...] Probably you may not have bothered too much on building the http response either the framework does it for you, or until you need to send the correct response.

The post shows you how to use the component to send and receive HTTP requests. Code is included showing how to make Response objects and set headers, content, cookies and HTTP response code. He also shows how to output the response and a more complete example of the entire flow. The post finishes up with an example of using Aura.Http to make a request to another site - in this case back to GitHub to get the users on a repository.

0 comments voice your opinion now!
aura project framework http request response tutorial



Community Events





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


threedevsandamaybe framework language podcast api series release project community introduction bugfix laravel interview code developer library application configure list wordpress

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