Christian WeiskePCNTL with mod_php and phancap 0.2 (22.11.2014, 20:41 UTC)

SemanticScuttle with website thumbnails Last week I released version 0.2.0 of phancap, the self-hosted website screenshot service.

phancap uses cutycapt to render website screenshots on a headless server, and it works fine most of the time. The problem here is most of the time; cutycapt has a nasty bug that makes it hang on some web sites and use 100% CPU, forever. This is not something that you want to run unattended on your server.

Process control

Fortunately, PHP has the pcntl extension that allows PHP scripts to fork and control processes. My idea was to let cutycapt run for at most 30 seconds and kill it if it did not exit in that time. This way, screenshot generation would fail for some URLs, but the server would not collect hundreds of never-ending processes.

The implementation wasn't that hard and worked fine on command line: It forked a child process that hung forever and killed it after 3 seconds.

After integrating it in phancap I noticed that it did not work. I was sure I had the pcntl extension installed and enabled, and it worked fine on CLI - just not when run under mod_php.

A user note in the PHP manual finally gave a hint why it failed:

"Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment."

At least for PHP 5.3.8 which I am using, and who knows how far back, it's not a matter of "should not", it's "can not". Even though I have compiled in PCNTL with --enable-pcntl, it turns out that it only compiles in to the CLI version of PHP, not the Apache module. As a result, I spent many hours trying to track down why function_exists('pcntl_fork') was returning false even though it compiled correctly. It turns out it returns true just fine from the CLI, and only returns false for HTTP requests. The same is true of ALL of the pcntl_*() functions.

To summarize: PHP's pcntl extension does not work on Apache with mod_php.

timeout to the rescue

After some searching I found the timeout command on my linux system, which came with the GNU core utilities.

timeout lets you specify how long to wait for a process to finish, and kills it with a user-defined signal if it's still running.

phancap utilizes timeout now when running cutycapt. With that I'm confident enough to let phancap run on my public server and use it on the SemanticScuttle demo site to provide screenshots for bookmarked web sites.

<script type="text/javascript" src="http://cweiske.de/tagebuch/js/shadowbox/shadowbox.js"> <script type="text/javascript"> Shadowbox.init({ continuous: true, displayCounter: false, displayNav: true, handleOversize: "resize" });
Link
Nomad PHPStatic Sites with Sculpin (22.11.2014, 17:37 UTC)

Presented by Chris Tankersley @dragonmantank We can build anything we want with PHP, be it a small little blog for ourselves to a giant world-spanning social media network. There are times though that we do not need all of the dynamic goodness that PHP brings and we just need a site that sits there. Sculpin …

The post Static Sites with Sculpin appeared first on Nomad PHP.

Link
Nomad PHPHarnessing the Power of Connected Data (22.11.2014, 17:30 UTC)

Presented by Jeremy Kendall @jeremykendall Connected data is the data of the present, and graph databases are the databases of the future. Learn how to harness the power of connected data in this quick introduction to Neo4j. Features hot chicken and barbecue.

The post Harnessing the Power of Connected Data appeared first on Nomad PHP.

Link
SitePoint PHPBuilding an Internationalized Blog with FigDice (22.11.2014, 17:00 UTC)

In part one of this two-part series I started looking at FigDice, a PHP templating system that takes a slightly different approach to most.

So far we’ve put together a very simple example website using Figdice. We’ve implemented a couple of pages, a Twitter feed and some template partials.

In this second and final part we’re going to add a simple blog to our example site, which allows us to look in more detail at Figdice’s concept of data feeds. We’ll also look at internationalization, translating some of the site’s content into a couple of additional languages.

The Code

I’ve created a separate repository for the code for this second part of the series, which you’ll find on Github. It expands upon the code we wrote in Part One.

There’s also an online demo.

Building a Simple Blog

Now let’s create a more complex example of a data feed, by implementing a simple blog.

First, create another feed class - this time for a blog.

Continue reading %Building an Internationalized Blog with FigDice%

Link
Anthony FerraraA Beginner's Guide To MVC For The Web (21.11.2014, 17:30 UTC)
There are a bunch of guides out there that claim to be a guide to MVC. It's almost like writing your own framework in that it's "one of those things" that everyone does. I realized that I never wrote my "beginners guide to MVC". So I've decided to do exactly that. Here's my "beginners guide to MVC for the web":

Read more »
Link
SitePoint PHPBuilding OctoberCMS Plugins: Google Analytics (21.11.2014, 17:00 UTC)

OctoberCMS is one of the rising stars in content management systems, and as in every CMS we need plugins to extend the functionality. In this article, we’re going to go through the basics of creating a plugin for October CMS.

October LOGO

What we’re building

Almost all websites need Google Analytics. We’re going to make a plugin that inserts the Google Analytics tracking code into the page using a component tag.

After inserting your tracking id in the settings form, you’ll need to insert the component tag on the pages that you want to track, or inside a partial.

{% component 'gaCode' %}

You can see the final result on github and try it out.

Managing Plugins

October has a plugins folder inside the root directory, where you can find, install, remove and develop plugins.

To manage your plugins, you can click the System > updates link. We have two different ways to manage our plugins.

Continue reading %Building OctoberCMS Plugins: Google Analytics%

Link
thePHP.ccPHP Un-Training on Mallorca (21.11.2014, 07:00 UTC)
Link
Nomad PHPFebruary 2015 – US (21.11.2014, 00:01 UTC)

Dependency Injection, Dependency Inversion, and You

Presented By
Jeff Carouth
February 19, 2015 20:00 CST

The post February 2015 – US appeared first on Nomad PHP.

Link
Nomad PHPFebruary 2015 – EU (21.11.2014, 00:01 UTC)

Laravel Forge: Hello World to Hello Production

Presented By
Joe Ferguson
February 29, 2014 20:00 CET

The post February 2015 – EU appeared first on Nomad PHP.

Link
SitePoint PHPGetting Started with FigDice (20.11.2014, 16:00 UTC)

Amongst the many templating systems out there, most work in pretty much the same way; variables are “injected” using some syntax or another, be it curly braces, percentage signs or whatever that library’s convention happens to be. They’ll usually have basic control structures, such as if...then and, of course, iteration.

FigDice, however, takes an altogether different approach. Inspired by PHPTAL - the subject of a future article - it gives the view layer the reponsibility of “pulling” in the data it requires, rather than relying on controllers to assemble and “push” it into the templates.

In this two-part series, I’m going to take a more detailed look at it, at how it works and how to use it.

Installation

You can get the code from the website, Github or, better still, Composer:

"figdice/figdice": "dev-master"

The library is also available as a .phar; you can download the latest version (direct link) or generate it yourself using figdice-make-phar.php, available in the Github repository.

Basic Usage

Let’s first look at FigDice at its most basic - creating and rendering a view.

To begin, create a new instance of the view:

$view = new \figdice\View();

Obviously, you’ll need to ensure the library is available - using Composer provides a suitable autoloader.

Next, you need to load in the appropriate template, relative to the current path:

$view->loadFile( '../templates/home.html' );

To render the template, call render():

$view->render(); // returns the HTML content

With that in mind, let’s start building some templates.

Continue reading %Getting Started with FigDice%

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP