 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
VG Tech Blog: Unit Testing with Streams in PHP
by Chris Cornutt December 08, 2011 @ 09:13:28
On the VG Tech blog today there's a new post from André Roaldseth about using PHPUnit to test PHP streams, basing the assertions on the data rather than the functionality itself.
Using the memory/temporary stream provided by php:// stream wrapper you can create a stream with read and write access directly to RAM or to a temporary file [using "php://memory"]. This gives you the possibilty to write unit tests that does not rely on a specific file, resource or stream, but rather on data provided by the test itself.
There's no specific code examples here, but you can refer to the stream wrappers section of the PHP manual for more details on this and other handy built-in streams. Once created, it can then be used just as any other stream resource can. This could be useful to provide mocks in your testing, replacing any other stream-able resource with a "memory" or "temp" placeholder.
voice your opinion now!
unittest stream memory temp wrapper mock object
DZone.com: Using a stream wrapper to access CouchDb attachments with PHP
by Chris Cornutt April 28, 2011 @ 10:45:27
On DZone.com today there's a new post from Gonzalo Ayuso about using a stream wrapper to access CouchDb database directly from PHP (via a call to its local file).
Thanks to a comment in my last post (many thanks Benjamin) I've discovered that it's possible to create a stream wrapper in PHP (I thought it was only available with a C extension). It's pretty straightforward to create the wrapper. Of course it's only an approach. We can create more functionality to our stram wrapper but at least this example meets my needs.
His wrapper uses a client from his Nov framework to open the stream to the given path and gives read and write methods to work with the data inside the database. Code for the wrapper class is included as well as a bit of example code showing how it can be used with the custom stream protocol. You can find the complete code here.
voice your opinion now!
couchdb stream wrapper database tutorial
Gonzalo Ayuso's Blog: Live video streaming with PHP
by Chris Cornutt September 20, 2010 @ 08:46:06
In a new post to his blog today Gonzalo Ayuso talks about video streaming and PHP. Well, okay, not so much using PHP for playing the video, more for the security and streaming around the streaming feeds.
For example we want to show videos only to registered users based on our authentication system. Imagine we're using sessions for validate users. That's means we cannot put the media in a public folder and point our media player to those files. We can obfuscate the file name but it'll remain public. In this small tutorial We're going to see how to implement it with PHP.
Since the video stream he wants to deal with is a live one (and not a single video file that can be read all at once) he shows how to use the output buffering functions in PHP to output small chunks of the data at a time with the correct headers attached.
voice your opinion now!
video stream live feed tutorial output buffer
Gonzalo Ayuso's Blog: Using a stream wrapper to access CouchDb attachments with PHP
by Chris Cornutt September 06, 2010 @ 08:15:22
In his continuing look at using CouchDb as a file system, Gonzalo Ayuso has posted this third part in the group of articles about using streams to connect your scripts to the database instance.
I'm still working in my filesystem with CouchDb. After creating a library to enable working with PHP and CouchDB (see the post here), and after using Monkey Patching to override standard PHP's filesystem functions. I've created another solution now. Thanks to a comment in my last post (many thanks Benjamin) I've discovered that it's possible to create a stream wrapper in PHP (I thought it was only available with a C extension).
He includes the code for the stream connection wrapper, a pretty simple script that parses the string it's given and opens a read/write stream to the source. There's also a "url_stat" method that will return to you the size of the stream in bytes. Then you just register the wrapper and go about your normal file system calls to use the CouchDb directly.
voice your opinion now!
couchdb stream wrapper attachment tutorial
Andrew Johnstone's Blog: Emailing Attachments Exim Filters and PHP streams
by Chris Cornutt June 01, 2010 @ 08:51:28
New on his blog today Andrew Johnstone has a post about email attachments how how the combination of Exim filters and PHP streams can make things much easier for you and your application.
Using exim filters we could add attachments at the delivery stage, therefore reducing overhead in constructing and injecting data into an email. The delivery of emails varied as to whether it was feasible to send as a BCC or whether there were placeholders intended for each individual recipient. As such the following addresses the worst case scenario of attachments with placeholders intended for each individual recipient.
They show how to use a PHP script (that uses streams to pull in the file data and information) hooked into an exim_filter to streamline the attachment process. Configuration file examples are included in the post as well as the PHP source for creating the filter.
voice your opinion now!
email attachment stream tutorial exim filter
Fabien Potencier's Blog: PHP Iterators and Streams are awesome
by Chris Cornutt May 26, 2010 @ 10:18:55
Fabien Potencier has written up a new post about two features of PHP he thinks are underused and very powerful - iterators and streams.
PHP also have a lot of awesome features; at least two of them are in my opinion largely underused: Iterators and Streams. You won't learn how to use them in this post, but with a simple example, I hope you will want to learn more about them.
He gives an example of a recent update he made to the sfFinder class for Symfony to use iterators instead of the current implementation. With the help of streams, making it translate its searching skills from the local machine out to an Amazon S3 instance was a relatively simple change to the stream's location.
voice your opinion now!
iterator stream example amazons3
Sameer Borate's Blog: Creating custom stream filters
by Chris Cornutt June 17, 2009 @ 07:56:28
In a new post to his blog Sameer takes a look at streams and filters in PHP applications, specifically how to set up a custom filter to attach to any stream.
In this post we will see how to create a custom stream filter. Streams, first introduced in PHP 4.3, provide an abstration layer for file access. A number of different resources besides files - like network connections, compression protocols etc. can be regarded as "streams" of data which can be serially read and written to.
Streams are the method "behind the scenes" for several of the PHP functions you already use (like fsockopen and file_get_contents). His example shows you how you can manually create a stream and attach a filter to it to replace URLs in the contents of the stream with the "[---URL---]" string and push it back to the standard output.
voice your opinion now!
filter custom tutorial stream
PHPro.org: Read Line From File (stream_get_line)
by Chris Cornutt April 23, 2009 @ 09:36:51
The PHPro.org website has a quick new tutorial about a method (using streams) to get the information from a certain line of a file.
Reading files in PHP can be a tricky business if not handled correctly. Most often when confronted with reading a line from, the nearest tool to hand is the file() function. The problem with using the file() function is that it reads the whole file into an array, and thus, into memory [...] A better, and more efficient way is to loop through the file stream using the stream_get_line() function. Care still needs to be taken to clear the buffer on each iteration, or the same problem could potentially arise as with the file() method.
The code calls fopen on the file and, while it's not the end of the file, uses the stream_get_line function to grab things a line at a time. This saves you from having to read in the entire file (like with a file_get_contents or file - especially good for large files.
voice your opinion now!
stream tutorial file line read streamgetline
|
Community Events
Don't see your event here? Let us know!
|