News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Matthias Noback:
Test Symfony2 commands using the Process component and asynchronous assertions
March 24, 2014 @ 10:49:13

Matthias Noback has a new post today showing you how to test Symfony2 commands that use the Process component. More specifically, his tests revolve around the ones that use asynchronous assertions in the testing to remove weird behaviors that could be caused by multiple processes running them simultaneously.

Usually you would test a console command using the ConsoleTester class as described in the official Symfony documentation. But we can not use it in this case. We need to isolate the process in order for pcntl_fork() to work correctly, otherwise the PHPUnit test runner itself will be forked too, which will have the effect of running all the following unit tests twice (which can have very strange effects on the test results).

He shows how to use the Process component to start up a new process (the daemon) and check that the PID file exists. He includes an example of a "probe" to determine what processes are running and preventing them from stepping on each other.

0 comments voice your opinion now!
symfony2 command process component asynchronous assertion unittest phpunit

Link: http://php-and-symfony.matthiasnoback.nl/2014/03/test-symfony2-commands-using-the-process-component-and-asynchronous-assertions/

Mikko Koppanen:
Working on images asynchronously
December 16, 2013 @ 10:45:35

Mikko Koppanen has a new post to his site today about working with images asynchronously - the "offline" processing of things like user uploaded images using a queuing system.

To get my quota on buzzwords for the day we are going to look at using ZeroMQ and Imagick to create a simple asynchronous image processing system. Why asynchronous? First of all, separating the image handling from a interactive PHP scripts allows us to scale the image processing separately from the web heads. [...] Secondly, separating the image processing from a web script can provide more responsive experience to the user. This doesn't necessarily mean faster, but let's say in a multiple image upload scenario this method allows the user to do something else on the site while we process the images in the background.

He also includes a "barebones" example of how the system would work. The first Worker script makes the connection to the queue system and sends the data off for handling. The second script does most of the actual work, pulling in the image and using Imagick to create a thumbnail image. Finally he includes an example of the use of the workers in combination to send the image data for processing.

0 comments voice your opinion now!
image asynchronous processing zeromq thumbnail imagick

Link: http://valokuva.org/working-on-images-asynchronously/

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

Segment.io:
How to Make Async Requests in PHP
February 06, 2013 @ 09:52:49

On the Segment.io blog there's a new post by Calvin talking about making asyncronous requests in PHP and three different approaches you could use, depending on your situation.

When designing client libraries to send data to our API, one of our top priorities is to make sure that none of our code affects the performance of your core application. That is tricky when you have a single-threaded, "shared-nothing" language like PHP. [...] Ideally, we like to keep the setup process minimal and address a wide variety of use cases. As long as it runs with PHP (and possibly a common script or two), you should be ready to dive right in. We ended up experimenting with three main approaches to make requests in PHP. Here's what we learned.

Their three suggestions don't involve external dependencies (like a queue server) and can operate pretty quickly:

  • Opening a socket and closing it before waiting for a response
  • Write to a log file (a pseudo-queue)
  • Fork a curl process (through something like exec)

They each have small code examples included with them and explanations as to their plusses and minuses. For their needs, the "forked curl" solution worked out the best, but check out the other options too - you might have different needs.

0 comments voice your opinion now!
asynchronous request socket curl log queue tutorial


Francois Zaninotto's Blog:
Node.js for PHP Programmers #1 Event-Driven Programming... and Pasta
January 26, 2012 @ 08:35:41

On his blog today Francois Zaninotto has a post that aims to introduce those with a PHP background to how Node.js works. In this first part of his series, he tries to explain the idea of event-driven programming - parallel processing of different parts of an application based on some action taken in the code.

For a PHP developer, asynchronicity is the most puzzling aspect of the Node.js runtime. It's simply a new way to write programs. And once you pass the first learning steps, event-driven programming opens a world of possibilities PHP programmers would never dream of. I'll try to explain you how it works, but first, let's talk about pasta.

In his "pasta" example, he shows how a typical PHP application would make a "Pan" object, call a "warm" action, "add olive oil", etc. All of this happens in sequence, though and takes 29 "minutes" to complete. To help things along, he implements an "EventLoop" class that handles tracking the timing and includes two methods to execute callbacks and delayed methods. He expands on this example with asynchronous objects and method calls to handle multiple things at once. He relates this to what Node.js offers - a built in event handling system, an included EventLoop object and native blocking I/O operations.

0 comments voice your opinion now!
nodejs programmer eventdriven pasta asynchronous


Gonzalo Ayuso's Blog:
Speed up PHP scripts with asynchronous database queries
October 11, 2010 @ 11:49:53

In a new post to his blog Gonzalo Ayuso has a suggestion for speeding up your scripts that use multiple database connections, possibly ones with larger queries that could take a while to run - asynchronous query handling.

That's the situation. A web application with 4 heavy queries. Yes I know you can use a cache or things like that but imagine you must perform the four queries yes or yes. As I say before the four database queries are heavy ones. 2 seconds per one. Do it sequentially, that's means our script will use at least 8 seconds (without adding the extra PHP time). Eight seconds are a huge time in a page load. So here I will show up a technique to speed up our website using asynchronous calls.

Since PHP doesn't really support threading, he works around it by creating a separate script for each of the queries (obviously only practical for special cases) as a self-contained unit. Then the "master" script that needs the results of the queries calls each of them via asynchronous curl class (simply named "Fork") that sends off the requests and waits for each result to come back as a json result set.

1 comment voice your opinion now!
database asynchronous query curl json


Kevin Schroeder's Blog:
Could your PHP application benefit from asynchronous computing?
October 05, 2010 @ 08:42:16

Kevin Schroeder has been conducting an informal poll about asynchronous computing in PHP applications and has posted some of the results (as well as the poll for those that didn't get their votes in) to his blog today.

Tis the season for Zendcon. I am going to be giving a talk at Zendcon called "Do You Queue". It will be about doing asynchronous computing in PHP. In order for me to gather some data I posted a twitpoll poll. The response has been pretty good. However, there have also been several misunderstandings as well.

He points out a few comments on the poll that talk about asynchronous processing being included in the language and dismiss it as something that other technology already does. He agrees that threads shouldn't be in PHP because it would break on of PHP's strongest features - the Shared Nothing architecture. Want to share your opinion? Vote on the poll and be heard!

0 comments voice your opinion now!
zendcon10 zc10 queue asynchronous poll results


Kevin Schroeder's Blog:
You want to do WHAT with PHP? Chapter 6 & 7
September 15, 2010 @ 08:16:53

Kevin Schroeder has posted excerpts from the sixth and seventh chapters from his "You Want To Do WHAT With PHP?" book.

Chapter 6 focuses on asynchronous processing and the excerpt talks about doing it with a little big of encryption on the side.

In the excerpt from Chapter 7 he looks at a more structured way to access files rather than just the random fopen or file_get_contents. There's a code example in this one showing how to get the header information off of a file for things like file type, last modified time, a header checksum and the file's permissions.

0 comments voice your opinion now!
book excerpt asynchronous processing file access


Daniel Jensen's Blog:
Database gearman worker in PHP example
August 16, 2010 @ 14:51:25

Daniel Jensen has a new post about using Gearman to do some simple database inserts asynchronously.

If you need to do a lot of inserts in your DB with a certain line of order they should be carried out in or with a clean-up script following after the inserts and you don't have to wait for a reply from MySQL, the answer to that problem might be this worker written in PHP for Gearman as an interface for your DB. A MySQL crash or a worker crash will have no impact on your inserts because they will just stay in the Gearman queue until the system is running again.

He includes a code snippet showing a sample database Gearman worker written in PHP to run simple database queries. His example uses a simple database connection (a basic wrapper around a mysql_query) and the line of code to run the worker.

0 comments voice your opinion now!
database gearman asynchronous example


Sameer Borate's Blog:
Parallel cURL execution in PHP
August 05, 2010 @ 09:56:05

New on his blog today Sameer Borate has a post looking at his method for making parallel connections with curl based on this library from Pete Wardens.

Most people use the 'easy' mode - in this mode when we issue multiple requests, the second request will not start until the first one is complete. This is known as synchronous execution, and this is the one we normally use. [...] In [multi] mode all requests can be handled in parallel or asynchronously. And it can be quite handy and time saving on many occasions.

He gives some code examples of how to use the library to simplify the curl connections and requests and pass the result off to a callback when it's done. His more practical example shows how to search for a set of terms on Google and return the results for output.

1 comment voice your opinion now!
parallel curl execution tutorial library asynchronous



Community Events











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


symfony2 release introduction opinion install facebook language security hhvm performance framework support unittest package composer database hack podcast component application

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