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

Freek Van der Herten:
Easily work with the Twitter Streaming API in PHP
Jan 16, 2017 @ 15:25:26

On his site ** has posted a tutorial showing you how to use the Twitter Streaming API from PHP with some help from the Phirehose package.

Twitter provides a streaming API with which you can do interesting things such as listen for tweets that contain specific strings or actions a user might take (e.g. liking a tweet, following someone,…). In this post you’ll learn an easy way to work with that API.

When researching on how to work with the streaming API in PHP it stumbled upon Phirehose. This package can authenticate and set up a connection with the streaming API.

Since the Phirehose API is a bit difficult to work with, he created a package (Laravel version) to help make it a bit easier. He then walks you through the integration of this service with a Laravel-based application, including showing you how to set up the app on the Twitter side and get the API key/secret for the connection. He shows how to add the Laravel package version's provider to the configuration and create a first stream type: listening for certain hashtags. He shows how the stream reacts to a simple tweet of his with the "#laravel" hashtag in a console application. He also includes another example showing a stream that listens for people performing actions on the current user's stream (like favoriting a tweet). You can find out more about the powerful Stream API in the official Twitter documentation for the service.

tagged: twitter streaming api tutorial package phirehose laravel

Link: https://murze.be/2017/01/easily-work-with-the-twitter-streaming-api-in-php/

SitePoint PHP Blog:
PHP Streaming and Output Buffering Explained
Sep 04, 2014 @ 15:17:44

The SitePoint PHP blog has a new performance-related post to the site today from Imran Latif. This new post looks at effective use of output buffering and streaming and explains how it works and some examples of its use.

As a PHP developer, I was wondering whether we can have something similar [to Streaming in Rails] in our favorite language? The answer is yes – we can easily have streaming in PHP applications with little effort, but in order to get this right we have to become familiar with some underlying concepts. In this article, we will see what streaming is, what output_buffering is and how to get our desired result under different webservers (Apache, Nginx) and PHP configurations (CGI, mod_php, FastCGI).

He starts off with a comparison of the two different methods, streaming and output buffering, and how they behave in the output of content. He then gets into some simple examples with PHP with various methods: a simple delay, chunking up output and finally using the actual output buffering handling PHP offers. He also includes an example of streaming content over an Ajax request with a simple test using the sleep function.

tagged: streaming output buffering tutorial introduction beginner ajax

Link: http://www.sitepoint.com/php-streaming-output-buffering-explained/

ReviewSignal Blog:
Long Running Processes in PHP
Aug 23, 2013 @ 16:29:03

On the ReviewSignal blog today there's a post looking at their use of long running PHP processes and how they got around some of the common problems.

Here at Review Signal, I use a lot of PHP code and one of the challenges is getting PHP to run for long periods of time. Here are two sample problems that I deal with at Review Signal that require PHP processes to run for long periods of time or indefinitely: data processing and Twitter streaming API data.

They talk some about their use of the PHP CLI, bash and cron to execute their scripts. There's a bit about the difference between executing a script in ssh versus cron and how to use "nohup" to have it execute in the background. They show how to set up a cron job and, more specifically, how their script pulls from the Twitter API via a bash script to check if it's already running.

tagged: long running process example twitter api streaming

Link: http://reviewsignal.com/blog/2013/08/22/long-running-processes-in-php/


Trending Topics: