Monday, February 25, 2013

Sending stream responses with Zend Framework 2, Part 1

Sending stream responses is a new feature in Zend Framework 2.1. This short introduction will help you getting startet on how to send stream responses in Zend Framework 2.
Most times an application would deliver file downloads or video streaming with static assets, delivered directly frm Apache or Nginx. But sometimes there are restrictions: Only logged-in users should be able to download this file, watch this content, perhabs even a more complicated permission system. Then the application needs to do some permission checks and stream the response.
In this example we assume a simple file download, we deliver the file as stream response, because this is much less memory consuming and more efficient, compared to grabbing the file content and pushing it to the response body of the default response object.

namespace Application\Controller;

use Zend\Http\Headers;
use Zend\Http\Response\Stream;
use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController
    public function fileAction()
        $file = '/path/to/my/file.txt';
        $response = new Stream();
        $response->setStream(fopen($file, 'r'));

        $headers = new Headers();
            'Content-Disposition' => 'attachment; filename="' . basename($file) .'"',
            'Content-Type' => 'application/octet-stream',
            'Content-Length' => filesize($file)
        return $response;

Even more complex use cases with download resume and speed limits are also possible in the future, but this is part of my next blog post about this topic. However you can see how easy it is to send stream responses with Zend Framework 2. As we return the response object directly in the controller, no view is created and rendered, too, so this is really a very fast operation.

Saturday, February 2, 2013

List of current php version in major linux distros

I tried to make a list of current php versions in major linux distributions. Please feel free to correct or add additional one per comment.

Distribution PHP Version
Ubuntu 16.04 Xenial 7.0.4
Ubuntu 15.10 Willy 5.6.11
Ubuntu 14.04 LTS Trusty 5.5.9
Ubuntu 12.04 LTS Precise 5.3.10
Ubuntu 12.10 Quantal
Debian 8 Jessie
Debian 7.5 Wheezy 5.4.4
Debian 6.0.6 Squeeze 5.3.3
Cent OS 6.3 5.3.3
Arch Linux 5.4.11
Fedora 18 5.4.9
Fedora 17 5.4.1
Mandriva 2011 5.3.20
Mandriva 2010 5.3.2
Mageia 2 5.3.19
OpenSUSE 12.2 5.3.15
OpenSUSE 13.1 5.4.20
OpenSUSE 13.2 5.6.1
Slackware 14 5.4.7
PCLinuxOS 5.3.8
Red Hat (Enterprise) Linux 6.3 5.3.3
Red Hat (Enterprise) Linux 7.0 RC 5.4.16
SUSE Linux Enterprise System 11 SP1 5.2.6
SUSE Linux Enterprise System 11 SP2 5.2.14
SUSE Linux Enterprise System 11 SP3 5.3.17