Archive for the ‘PHP’ Category

Amazon PHP SDK v1.4.7 set_region bug for EC2: DNS names not properly resolved

Saturday, December 3rd, 2011

Version 1.4.7 of the Amazon PHP SDK added the new Oregon region (along with the United States government private GovCloud region) but introduced a bug rendering the whole library useless as it cannot resolve the correct DNS names.

Prior to v1.4.7, the AmazonEC2 library used these constants (in /usr/share/php/AWSSDKforPHP/services/ec2.class.php):

    /*%******************************************************************************************%*/
    // CLASS CONSTANTS

    /**
     * Specify the default queue URL.
     */
    const DEFAULT_URL = 'ec2.amazonaws.com';

    /**
     * Specify the queue URL for the US-East (Northern Virginia) Region.
     */
    const REGION_US_E1 = 'us-east-1';

    /**
     * Specify the queue URL for the US-West (Northern California) Region.
     */
    const REGION_US_W1 = 'us-west-1';

    /**
     * Specify the queue URL for the EU (Ireland) Region.
     */
    const REGION_EU_W1 = 'eu-west-1';

    /**
     * Specify the queue URL for the Asia Pacific (Singapore) Region.
     */
    const REGION_APAC_SE1 = 'ap-southeast-1';

    /**
     * Specify the queue URL for the Asia Pacific (Japan) Region.
     */
    const REGION_APAC_NE1 = 'ap-northeast-1';

And the code used to reconstruct the DNS entry was

    /**
     * This allows you to explicitly sets the region for the service to use.
     *
     * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_EU_W1>, or <REGION_APAC_SE1>.
     * @return $this A reference to the current instance.
     */
    public function set_region($region)
    {
        $this->set_hostname('http://ec2.'. $region .'.amazonaws.com');
        return $this;
    }

With the upgrade to v1.4.7, those constants were changed to a FQDN, while the set_region() function was not changed at all:

    /*%******************************************************************************************%*/
    // CLASS CONSTANTS

    /**
     * Specify the queue URL for the United States East (Northern Virginia) Region.
     */
    const REGION_US_E1 = 'ec2.us-east-1.amazonaws.com';

    /**
     * Specify the queue URL for the United States West (Northern California) Region.
     */
    const REGION_US_W1 = 'ec2.us-west-1.amazonaws.com';

    /**
     * Specify the queue URL for the United States West (Oregon) Region.
     */
    const REGION_US_W2 = 'ec2.us-west-2.amazonaws.com';

    /**
     * Specify the queue URL for the Europe West (Ireland) Region.
     */
    const REGION_EU_W1 = 'ec2.eu-west-1.amazonaws.com';

    /**
     * Specify the queue URL for the Asia Pacific Southeast (Singapore) Region.
     */
    const REGION_APAC_SE1 = 'ec2.ap-southeast-1.amazonaws.com';

    /**
     * Specify the queue URL for the Asia Pacific Northeast (Tokyo) Region.
     */
    const REGION_APAC_NE1 = 'ec2.ap-northeast-1.amazonaws.com';

    /**
     * Specify the queue URL for the United States GovCloud Region.
     */
    const REGION_US_GOV1 = 'ec2.us-gov-west-1.amazonaws.com';

So, for instance, if you were using REGION_US_W1 before,
the old SDK would resolve the url to ‘http://ec2.us-west-1.amazonaws.com’ using set_region()

As of v1.4.7, REGION_US_W1 was changed to
‘ec2.us-west-1.amazonaws.com’
so now set_region() builds the url as the non very pretty
‘http://ec2.ec2.us-west-1.amazonaws.com.amazonaws.com’

and triggers this PHP fatal error

PHP Fatal error:  Uncaught exception 'RequestCore_Exception' with message 'cURL resource: Resource id #62; cURL error: Couldn't resolve host 'ec2.ec2.us-west-1.amazonaws.com.amazonaws.com' (6)' in /usr/share/php/AWSSDKforPHP/lib/requestcore/requestcore.class.php:824
Stack trace:
#0/usr/share/php/AWSSDKforPHP/sdk.class.php(1185): RequestCore->send_request()

To fix the error, modify set_region to:

    public function set_region($region)
    {
        //$this->set_hostname('http://ec2.'. $region .'.amazonaws.com');
        $this->set_hostname('http://'.$region);
        return $this;
    }

——————————————————————
Update 12/07/2011:
Version 1.4.8 of the PHP SDK corrects the bug.

Administer your ghost pages shared by the new Facebook Like button

Sunday, April 25th, 2010

——————
Note: Use this post to talk about the Wordpress Facebook Like button plugin
——————

If you’re using THE Facebook Like button plugin (the first one the market and most robust ;-) hosted on Wordpress, you want to be able to administer your pages.

It’s nice to have lots of people like your pages, but it’s even better if you can also send all those Facebook user a message too.
For instance you could post updates about your page, or offer products and services (or advertisement) in a pinpoint accuracy targeted way.

The main revolution Facebook announced at f8 on April 21st is that every legacy web page on the web can now be turned into a Facebook page.

Here is how it works in practice and how to administer your blog pages on Facebook.

You will be able to not only view all the Facebook users who Liked your page, but see statistics and also send all of them messages directly to their Facebook feeds.

Pretty powerful spammy viral tool here.

The First solution if you use Wordpress and the Facebook Like button plugin is to simply configure the plugin by entering your Facebook ID in the Settings page.

It will make an “Admin Page” link appear next to the number of shares you have so far for the page:

Like button with Admin link

And voilà! You’re done. The meta data will be added automatically to the header.

The Second solution, if you don’t use the plugin, or if you use another blogging software or even a standalone website is to add some meta tags in the html header.

Here are the steps to do it manually in Wordpress.

1/ Modify you Wordpress header

Edit your Wordpress header file…

bash# cd ~/wordpress/wp-content/themes/<THE DIRECTORY OF YOUR THEME>/
bash# vi header.php

… by adding HTML tag attributes (very top of the file):

<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:og="http://opengraphprotocol.org/schema/"
        xmlns:fb="http://www.facebook.com/2008/fbml" <?php language_attributes(); ?>>

… and by adding these meta tags in the header section of the header.php file:

<meta property="fb:admins" content="YOUR OWN FACEBOOK ID"/>
<meta property="og:title" content="<?php the_title_attribute( $args ); ?>" />
<meta property="og:type" content="blog" />
<meta property="og:url" content="<?php echo get_permalink($post->ID); ?> "/>
<meta property="og:image" content="http://blog.bottomlessinc.com/wp-content/uploads/2010/04/logo.jpg" />

Don’t forget to replace “YOUR OWN FACEBOOK ID” with your own numerical Facebook ID.
(example: “68310606562″ if you are Mark Zuckerberg)

Be careful to use the proper Facebook ID as once people start liking your post, you cannot change this ID anymore for security reasons.
You can only append new Facebook IDs (separate them with commas) and cannot replace the original Facebook ID which always has to appear first.
So in the previous example the first Facebook ID will always have to be 68310606562, otherwise Facebook will return this error when trying to like the page:

You previously specified 68310606562 as the leading admininstatory in the ‘fb_admins’ meta tag. The ‘fb_admins’ tag now specifies that 666 is the leading administrator. That needs to be changed back.

Also you can’t remove the Admin ID anymore once it’s been entered, or you will get this error:

Your page no longer includes any admininstrator IDs, even though you’ve specified one before. You must include 68310606562 in the ‘fb_admins’ meta tag, and it must be the very first one if there are many.
Facebook ©2010

Thanks to Tim at Hyperarts for the code.

2/ Administer your Facebook Ghost Pages

Now refresh your page, click on the “Like” button and notice the link to your newly created Facebook admin page as in this screen shot:

Facebook Like Admin Page

Clicking on the “Admin Page” link will redirect you to Facebook, which is only a regular Facebook Page automatically created with the picture specified in your header meta tag as profile picture.

It looks like this:

Facebook Like Admin Page on Facebook

Notice at the top the message in the yellow box confirming your are administrator of the page:

Administer Your Page.

You are seeing this page because you are an administator. All other users are directed to http://blog.bottomlessinc.com/2010/04/creating-a-wordpress-plugin-add-the-new-facebook-like-button-to-your-posts/, but you are being directed here so you can manage your fans and publish stories to your fans’ News Feeds.

(hum, looks like Facebook doesn’t know how to spell administrator).

Facebook provides a list of all the pages you administer in one convenient place.

Facebook is definitely mirroring the whole entire world wide web with these ghost pages that will blossom like mushrooms this spring.

From this Facebook page you can:
- see all Facebook users who Liked your page (formerly known as “Fans”)
- see statistics about the page (“insights”)
- post a message to your page wall

You will then start getting a weekly email update from Facebook listing the statistics of all your the different pages that were created.

For each page you will see:
- number of fans this week and number of total fans (hum, Facebook still calls them “Fans” here, I guess it didn’t sound right to call them “Likers”?)
- Wall Posts, Comments, and Likes this week (and last week)
- visits to your page this week (and visits last week)
- a direct link to Update your fans

Posting a message to your page wall will make your message appear in the Stream of every user who liked your page.

Virality is back (for external website that is, not Facebook applications)

Creating a Wordpress plugin: Add the new Facebook Like button to your posts

Thursday, April 22nd, 2010

——————
Note: Here is the latest version of the Facebook Like Wordpress Plugin for the impatient (and people not interested in the technical details but just looking for a solution working out of the box).

There is also the Official Wordpress page (from which you should rate the plugin and report it works, thanks).

This blog post is about the process of creating the plugin itself, so if you use the plugin directly you don’t have anything else to do than just installing it.
No coding necessary.
Otherwise you would add things manually and then the plugin would do the same again.
Jump to section 7/ Installation of the plugin if you just want to use the final product working out of the box.
Check also section 8/ Customize the plugin for help on configuring it when installed.
——————

Writing a Wordpress plugin is fairly simple provided you know PHP and follow the well documented process at wordpress.org.

If you’re in a hurry and just want a simple functionality, this guide is what you need.

Here’s a shortened version on how to create a Wordpress plugin that will add the new Facebook “Like” button announced yesterday at f8 to your posts and/or pages.

Facebook new Like button

Simple yet customizable as we’ll still provide a settings page for the plugin.

Facebook new Like button Wordpress plugin settings

1/ Optional Preparation

You can write a plugin and release it without submitting it to the official Wordpress directory.

Submitting your plugin to the Wordpress directory means your plugin must be release under GPLv2, so be aware of that before hand if it bothers you.

Some benefits of submitting to the directory are:
- faster distribution (users can find it easily)
- free SVN hosting
- packaging of the different versions
- access to analytics (number of downloads, …)

If you intend to submit your plugin to the directory, it may be a good idea to first look up which names are available as you may want to name your files and functions according to this name.
Check out the Wordpress plugin SVN to see what’s already taken.

2/ Create the plugin folder

bash# cd ~/wordpress/wp-content/plugins/
bash# mkdir like
bash# cd like/
bash# touch readme.txt
bash# touch tt_like_widget.php

We really need only two files:
- the readme file to describe the plugin,
- the actual code of the plugin in the php file (name it whatever you want).

3/ Write the Readme file

A basic Readme file looks like this:

=== Like ===
Contributors: bottomlessinc
Donate link: http://blog.bottomlessinc.com/
Tags: share, facebook, like, button, social, bookmark, sharing, bookmarking, widget
Requires at least: 2.3
Tested up to: 2.9.2
Stable tag: 1.0

The Facebook Like Button Widget adds a 'Like' button to your Wordpress blog posts.

== Description ==
Let your readers quickly share your content on Facebook with a simple click.

== Installation ==

1. Upload `tt_like_widget.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. (Optional) Customize the plugin in the Settings > Like menu

== Frequently Asked Questions ==

= Is Like free? =

Yes

== PHP Version ==

PHP 5+ is preferred; PHP 4 is supported.

== Changelog ==

= 1.0 =
Stable version

You can get more information on the readme file with this more elaborated example.
Wordpress also provides a readme validator the way W3C does for XHTML validation.

4/ Write the PHP file

Only one function will be called in the file, the init function:

tt_like_init();

It does three main things:
- register and retrieve the parameters of your plugin if you have any (you will be able to set those in the settings page)
- register your own function to be called when an event happens, here an event called ‘the_content’ called every time the content of the post is rendered. Our plugin here will just append some content at the end of the post content.
- register your own function to be called to render the settings page in your Wordpress admin panel so you can customize your plugin.

function tt_like_init()
{
    add_option('tt_like_width', '450');
    add_option('tt_like_layout', 'standard');
    add_option('tt_like_showfaces', 'true');

    $tt_like_settings['width'] = get_option('tt_like_width');
    $tt_like_settings['layout'] = get_option('tt_like_layout');
    $tt_like_settings['showfaces'] = get_option('tt_like_showfaces') === 'true';

    add_filter('the_content', 'tt_like_widget');
    add_filter('admin_menu', 'tt_like_admin_menu');
}

The add_option function is provided by the Wordpress API and registers the default values of your options.
The previously saved setting are retrieved using get_option() and stored in our global variable we named ‘tt_like_settings’.
Our function tt_like_widget() will get called every time the content of the post needs to be rendered as we registered it with the add_filter() function.
In a similar manner, tt_like_admin_menu() will get called to render the settings page in the Wordpress admin interface.

The tt_like_widget() function is pretty straight forward: just append whatever you want to append to the $content variable.

function tt_like_widget($content)
{
     $showfaces = ($tt_like_settings['showfaces']=='true')?"true":"false";
     $url = urlencode(get_permalink()) . "&amp;layout="  . $tt_like_settings['layout']
                                . "&amp;show_faces=" . $showfaces
                                . "&amp;width=" . $tt_like_settings['width'];
     $button = '<iframe src="http://www.facebook.com/plugins/like.php?href='.$url.'" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:'.$tt_like_settings['width'].'px; height: 50px"></iframe>';
     $content .= $button;
     return $content;
}

Here we build a Facebook Like button which is just an iframe pointing to a Facebook URL having the URL of the current post as parameter.
It means we need to retrieve the URL of the current post dynamically, this is done using get_permalink()
This is also the place we use our settings to produce a Facebook Like button customized according to the settings on the admin page.

And now for the settings on the admin page. We basically build an html form that will record the user preferences.

function tt_plugin_options()
{
    $tt_like_layouts = array('standard', 'button_count');

    <div class="wrap">
    <h2>Facebook Like Button</h2>

    <form method="post" action="options.php">
    <?php
        if (tt_get_wp_version() < 2.7) {
            wp_nonce_field('update-options');
        } else {
            settings_fields('tt_like');
        }
    ?>

    <table class="form-table">
        <tr valign="top">
            <th scope="row"><?php _e("Width:", 'tt_like_trans_domain' ); ?></th>
            <td><input type="text" name="tt_like_width" value="<?php echo get_option('tt_like_width'); ?>" /></td>
        </tr>
        <tr>
            <th scope="row"><?php _e("Layout:", 'tt_like_trans_domain' ); ?></th>
            <td>
                <select name="tt_like_layout">
                <?php
                    $curmenutype = get_option('tt_like_layout');
                    foreach ($tt_like_layouts as $type)
                    {
                        echo "<option value=\"$type\"". ($type == $curmenutype ? " selected":""). ">$type</option>";
                    }
                ?>
                </select>
        </tr>
        <tr>
            <th scope="row"><?php _e("Show faces:", 'tt_like_trans_domain' ); ?></th>
            <td><input type="checkbox" name="tt_like_showfaces" value="true" <?php echo (get_option('tt_like_showfaces') == 'true' ? 'checked' : ''); ?>/></td>
        </tr>
    </table>

     <?php if (tt_get_wp_version() < 2.7) : ?>
       <input type="hidden" name="action" value="update" />
       <input type="hidden" name="page_options" value="tt_like_width, tt_like_layout, tt_like_verb, tt_like_colorscheme, tt_like_showfaces"/>
    <?php endif; ?>

    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
    </p>

    </form>
    </div>
}

Here we have some code for an input box, a dropdown menu and a checkbox as example.
There is some handling for earlier version of Wordpress.
Refer to the options page help for further information.
The _e() function is here for internationalization.

5/ Submit your plugin to the Wordpress directory

Submit your new plugin to the directory by providing a unique name for it.

You will then be able to upload it to the SVN repository.

6/ Check in your code in the SVN repository

After Wordpress approves your plugin (it took 3 days for this one), you can check your code in the provided SVN link.

bash# mkdir ~/my_wp_plugin
bash# cd ~/my_wp_plugin
bash# svn co http://svn.wp-plugins.org/like
A    like/trunk
A    like/branches
A    like/tags
Checked out revision 233010.
bash# cp ~/wordpress/wp-content/plugins/like/readme.txt trunk/
bash# cp ~/wordpress/wp-content/plugins/like/tt_like_widget.php trunk/
bash# svn add trunk/*
A         trunk/readme.txt
A         trunk/tt_like_widget.php
bash# svn ci -m "First stable version"
Authentication realm: <http://svn.wp-plugins.org:80> WordPress.org Subversion
Username: bottomlessinc
Password for 'bottomlessinc': ****
Adding         trunk/readme.txt
Adding         trunk/tt_like_widget.php
Transmitting file data ..
Committed revision 233012.
bash#

Now you can tag the revision of the plugin as your first version.

bash# svn cp trunk tags/1.0
A         tags/1.0
bash# svn ci -m "Tagging v1.0"
Adding         tags/1.0
Adding         tags/1.0/readme.txt
Adding         tags/1.0/tt_like_widget.php
Committed revision 233013.
bash#

Now that your code is checked in with the mandatory readme.txt file and you tagged the version 1.0 of your SVN to match the Stable tag: 1.0 in readme.txt, Wordpress will do all the rest and package it for you.

It will be available to a URL resembling http://wordpress.org/extend/plugins/like making it accessible to all Wordpress user and providing you download statistics and feedbacks from users.

You can also promote your plugin further by submitting it to wp-plugins.

7/ Installation of the plugin

Here is the complete code for the widget:

Facebook Like Wordpress Plugin (Latest Version)

Unzip it in your plugin directory.

bash# cd ~/wordpress/wp-content/plugins/
bash# wget http://blog.bottomlessinc.com/wp-content/uploads/2010/04/like.zip
bash# unzip like.zip

Then go to the Wordpress admin dashboard, activate it, and optionally customize it in the settings page.

8/ Customize the plugin

The plugin works out of the box without configuration as it uses the IFRAME version of the button.

Optionally you can use the XFBML version but it requires more setup and a better knowledge of the Facebook platform as you will need to create a Facebook Application and enter its App ID in the settings page of the plugin.

Which one to choose, IFRAME or XFBML?

It really depends on how technical you are.
If you are not, stick with the default settings using the IFRAME version.
If you are technical you can venture in the XFBML version, but even there you will hit snags as Facebook is notorious for producing unstable Javascript and not getting things to work the first time (a daily struggle when you develop Facebook applications).

With XFBML, the user who clicked the Like button can add a comment that will be attached to the post on his profile.

Facebook XFBML Like button comment

The benefit of using XFBML is purely real estate: provided the user not only clicks the button but adds a comment, the profile post will now include the image you entered in the Settings of the plugin along with an excerpt of the article.

For comparison here is the one liner you will see if using IFRAME or if using XFBML when the user did not add a comment…:
Facebook Like button wallpost IFRAME

… and here is the profile post the user will generate when adding a comment with the XFBML version of the button:
Facebook Like button wallpost XFBML

Even though Facebook provides a simplified interface to generate a new Application, it doesn’t work right away.

When I first set it up I had this message when clicking the button:

The application ID specified within the “fb:app_id” meta tag is not allowed on this domain. You must setup the Connect Base Domains for your application to include this domain.
Facebook ©2010

When editing the settings of the Application itself, I couldn’t see anything wrong, and hit the “Save Changes” button without modifying anything.
Surprisingly it raised this error, refusing to save the (non existing) changes:

Validation failed.

Connect URL must point to a directory (i.e., end with a “/”) or a dynamic page (i.e., have a “?” somewhere).

In this case just edit the Application, go to the “Connect” tab and in the first field called “Connect URL”, make sure your website ends with a forward slash.
For instance I had to manually change my Facebook Connect URL from “http://bottomlessinc.com” to “http://bottomlessinc.com/” to make things work.

And even after that, when using the XFBML version the button doesn’t show up in around 20% of the page refresh.
That’s why sticking with the default IFRAME version is more reliable.

There is also a chance that adding a slash to your Connect URL will solve the problem of the Like button blinking (showing up as pressed then right away as unpressed).
During this blinking of the button you can see the message “You like http://example.com” which disappears also right away.

If you use the XFBML version of the plugin, you must provide the numerical Facebook ID of the Facebook user you will use to manage the pages.
Otherwise people clicking on the Like button will receive this error:

You failed to provide a valid list of administators. You need to supply the administors using either a “fb:app_id” meta tag, or using a “fb:admins” meta tag to specify a comma-delimited list of Facebook users.

Did you find this post useful? Like it on Facebook :-) and Spare a few cents:

Enabling Memcached on BlueHost

Thursday, March 11th, 2010

Bluehost is a pretty good web hosting company, cheap and leaving you in total control of your website.
That is if you know your way around.
I highly recommend them for dirt cheap hosting yet access to powerful features.

A common complaint against any cheap hosting is the lack of memcached installation by default.
It really doesn’t make sense even business-wise for them because memcached would allow to use less CPU/Memory per site hosted, meaning less total servers, meaning less power drawn, meaning big savings.
The hosting plans charging usually a fixed amount per month or year, reducing CPU/Memory/Servers would really make sense as the savings would be on directly on them.

Anyway, now we need to setup memcached ourselves on a machine we don’t have root access to.
No big deal, we will just have to compile everything ourselves.

Here’s how.

1/ Create an installation folder.

As we cannot write to /usr/, we cannot install any software system wide, so everything will remain local in our home folder.
Let’s call it ~/install/
It will be where you install all your compiled software, acting like the /usr/ folder we don’t have access to.

bash# mkdir ~/install

2/ Compile libevent

Why libevent? Because we will need it later to compile memcached.

bash# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
bash# tar zxf libevent-1.4.13-stable.tar.gz
bash# cd libevent-1.4.13-stable
bash# ./configure -prefix=~/install/
bash# make
bash# make install

libevent is now neatly installed in our home directory at ~/install/

3/ Compile memcached

bash# wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
bash# tar xzf memcached-1.4.4.tar.gz
bash# cd memcached-1.4.4
bash# ./configure --with-libevent=~/install/ --prefix=~/install/
bash# make
bash# make install

Neat, now we have memcached installed in ~/install/bin/, so let’s try to run it.

bash# cd ~/install/bin
bash# ./memcached
failed to set rlimit for open files. Try running as root or requesting smaller maxconns value.
bash# ./memcached -c 100
^CSIGINT handled
bash#

So we hit a limitation: as we’re not root, our memcached server is limited to only 100 connections instead of the default 1024.
Maybe we can live with that.

Now the server part is done, we need to be able to use the PHP commands to communicate with memcached.
This is found in the PEAR packages.

4/ Install the PHP memcache client

(the memcache client doesn’t have the ‘d’ at the end)

bash# pecl install memcache
downloading memcache-2.2.5.tgz ...
Starting to download memcache-2.2.5.tgz (35,981 bytes)
..........done: 35,981 bytes
11 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
Enable memcache session handler support? [yes] :
Notice: Use of undefined constant STDIN - assumed 'STDIN' in CLI.php on line 304

Warning: fgets(): supplied argument is not a valid stream resource in CLI.php on line 304

Warning: fgets(): supplied argument is not a valid stream resource in /root/lib/php/PEAR/Frontend/CLI.php on line 304
building in /usr/local/src/pear/pear-build-bottoml8/memcache-2.2.5
ERROR: could not create build dir: /usr/local/src/pear/pear-build-bottoml8/memcache-2.2.5

Ouch, we’re not root so pecl fails.
No big deal: pecl already downloaded memcache-2.2.5.tgz for us, let’s compile it manually.

bash# tar xzf memcache-2.2.5.tgz
bash# cd memcache-2.2.5
bash# phpize
bash# ./configure --prefix=~/install/
bash# make
bash# make test
bash# make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20060613/
cp: cannot create regular file `/usr/lib/php/extensions/no-debug-non-zts-20060613/#INST@7000#': Read-only file system
make: *** [install-modules] Error 1
bash#
bash# ls modules/
./  ../  memcache.so*
bash# cp memcache.so ~/install/lib/

Ok, make install failed, but we have already what we need: memcache.so in the memcache-2.2.5/modules/ directory.
It’s the extension we need to load in PHP (in the php.ini file) so we can use the PHP commands to access memcached.
We just moved it to ~/install/lib/ so it’s comfy with the other libraries we compiled earlier (libevent and memcached).

5/ Load the memcache module for PHP

Now for the tricky part:
As we don’t have root access, we cannot just change the server’s php.ini file to include our freshly brewed memcache.so and restart Apache to make the changes taken into account.

But Bluehost provides us with a neat way to use our own php.ini file.
By default this option is disabled.
In their cPanel it’s listed under the category ‘Software / Services’ as ‘PHP Config’.

By default the setting is Standard PHP5, we need to change that to the third option: PHP5 (FastCGI)
It will directly load the php.ini it finds in your ~/public_html/ directory.

On this same page of the cPanel, there’s an interesting button “INSTALL PHP.INI MASTER FILE”.
Just click it and magically the server’s php.ini file is copied in ~/public_html/php.ini.default

It’s now our base php.ini we’ll use to load memcache. Let’s edit it.

bash# cd ~/public_html/
bash# mv php.ini.default php.ini
bash# vi php.ini

In php.ini, find the line that reads:
extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20060613″
and replace it with
extension_dir = “/home/your_bluehost_user_name/install/lib”
so that we have access to our memcache.so lib.
At the end if php.ini, before the last line that loads the Zend Optimizer, include this line to load memcache.so:
extension=memcache.so

There should be some other libraries being loaded here:
;extension=pdo.so
;extension=pdo_sqlite.so
;extension=sqlite.so
;extension=pdo_mysql.so

As we changed the extension_dir path these libraries are not accessible anymore so you can just comment them.
extension_dir does not support listing multiple directories so I wish we didn’t have to do that.
At some point there was a proposal to make it happen, don’t know if it’s implemented yet, I couldn’t find anything about it.
Worst case scenario if you need PDO (and you probably do), you just need to compile it and install it in ~/install/lib/

Now that php.ini is modified, the server will pick up the configuration automagically.
But you may have to wait a little bit as php.ini will not be read again right away, you have to wait for the next poll, a few minutes.

6/ Let’s use memcached!

Now everything’s installed, let’s finally use memcached.

Create a memcache.php test file that will connect to memcached and just return the server version:

<?php
$memcache = new Memcache;
$memcache->addServer('localhost', 11211);
$memcache->connect('localhost', 11211);

echo $memcache->getVersion();
?>

Start the memcached in verbose mode so we can see our connection arriving:

bash# cd ~/install/bin/
bash#  ./memcached -h
memcached 1.4.4
-p <num>      TCP port number to listen on (default: 11211)
-U <num>      UDP port number to listen on (default: 11211, 0 is off)
-s <file>     UNIX socket path to listen on (disables network support)
-a <mask>     access mask for UNIX socket, in octal (default: 0700)
-l <ip_addr>  interface to listen on (default: INADDR_ANY, all addresses)
-d            run as a daemon
-r            maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num>      max memory to use for items in megabytes (default: 64 MB)
-M            return error on memory exhausted (rather than removing items)
-c <num>      max simultaneous connections (default: 1024)
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u <username> user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            verbose (print errors/warnings while in event loop)
-vv           very verbose (also print client commands/reponses)
-vvv          extremely verbose (also print internal state transitions)
-h            print this help and exit
-i            print memcached and libevent license
-P <file>     save PID in <file>, only used with -d option
-f <factor>   chunk size growth factor (default: 1.25)
-n <bytes>    minimum space allocated for key+value+flags (default: 48)
-L            Try to use large memory pages (if available). Increasing
              the memory page size could reduce the number of TLB misses
              and improve the performance. In order to get large pages
              from the OS, memcached will allocate the total item-cache
              in one large chunk.
-D <char>     Use <char> as the delimiter between key prefixes and IDs.
              This is used for per-prefix stats reporting. The default is
              ":" (colon). If this option is specified, stats collection
              is turned on automatically; if not, then it may be turned on
              by sending the "stats detail on" command to the server.
-t <num>      number of threads to use (default: 4)
-R            Maximum number of requests per event, limits the number of
              requests process for a given connection to prevent
              starvation (default: 20)
-C            Disable use of CAS
-b            Set the backlog queue limit (default: 1024)
-B            Binding protocol - one of ascii, binary, or auto (default)
-I            Override the size of each slab page. Adjusts max item size
              (default: 1mb, min: 1k, max: 128m)
bash#
bash# ./memcached -c 100 -vvv -l 127.0.0.1
slab class   1: chunk size        96 perslab   10922
slab class   2: chunk size       120 perslab    8738
slab class   3: chunk size       152 perslab    6898
slab class   4: chunk size       192 perslab    5461
...
slab class  40: chunk size    616944 perslab       1
slab class  41: chunk size    771184 perslab       1
slab class  42: chunk size   1048576 perslab       1
<26 server listening (auto-negotiate)
<27 send buffer was 124928, now 268435456
<27 server listening (udp)

---- Access the memcache.php file here in your browser ----

<28 new auto-negotiating client connection
<29 new auto-negotiating client connection
29: going from conn_new_cmd to conn_waiting
29: going from conn_waiting to conn_read
29: going from conn_read to conn_parse_cmd
29: Client using the ascii protocol
<29 version
>29 VERSION 1.4.4
29: going from conn_parse_cmd to conn_write
29: going from conn_write to conn_new_cmd
29: going from conn_new_cmd to conn_waiting
29: going from conn_waiting to conn_read
28: going from conn_new_cmd to conn_waiting
28: going from conn_waiting to conn_read
28: going from conn_read to conn_closing
<28 connection closed.

Tada! And magically the browser is displaying a magnificent “1.4.4“.

You got yourself a memcached server running on BlueHost.

Did you find this post useful? Buy this man a beer:

Display APC cache statistics

Tuesday, March 9th, 2010

Use apc_cache_info()

echo "<pre>".print_r(apc_cache_info())."</pre>"

Array
(
    [num_slots] => 2000
    [ttl] => 0
    [num_hits] => 9
    [num_misses] => 3
    [start_time] => 1123958803
    [cache_list] => Array
        (
            [0] => Array
                (
                    [filename] => /path/to/apc_test.php
                    [device] => 29954
                    [inode] => 1130511
                    [type] => file
                    [num_hits] => 1
                    [mtime] => 1123960686
                    [creation_time] => 1123960696
                    [deletion_time] => 0
                    [access_time] => 1123962864
                    [ref_count] => 1
                    [mem_size] => 677
                )
            [1] => Array (...iterates for each cached file)
)

CakePHP: Convert a complex find condition from 1.1 to 1.3

Sunday, March 7th, 2010

First, findAll() no longer exists in 1.3, you need to use find(‘all’).
Then the conditions array structure is different, moving from a key/value pair array to an array with values only.

This is the query in 1.1:

 $conditions = array("OR" => array(
      'Item.expiration'       => 0,
      'Item.expiration >'     => "NOW()"
    )
 );
 $items = $this->Item->findAll($conditions);

Re-written for 1.3:

$conditions = array("OR" => array(
      'Item.expiration = 0',
      'Item.expiration > NOW()' // single string
    )
 );
 $params = array(
   'conditions'    => $conditions
);
 $items = $this->Item->find('all', $params);

Source

Installing the APC cache for PHP to speed up your server

Tuesday, March 2nd, 2010

There is a simple, no friction way of improving the performance of your PHP web server by just installing the APC cache.

It will cache the php op-code and serve php files faster.

Basically PHP is a scripting language, meaning every time you load a PHP page, the server has to:
1/ read the source code file (the one you programmed in PHP language, with extension .php)
2/ compile the file into executable code (language understood by the computer), a binary file
3/ execute the generate code

If nothing has changed to your source code file, the every time somebody loads the page from your server steps 1/ and 2/ will be executed again.

APC will just cache the result of steps 1/ and 2/, store them into the binary file and execute this binary at every page load.

As it’s a one line installation and nothing needs to be changed to your installation, it’s a no brainer everyone should do it.

bash# pecl search apc
Retrieving data...0%
MATCHED PACKAGES, CHANNEL PECL.PHP.NET:
=======================================
PACKAGE STABLE/(LATEST) LOCAL
APC     3.1.7 (beta)          Alternative PHP Cache
bash#
bash# pecl install apc
downloading APC-3.1.6.tar ...
Starting to download APC-3.1.6.tar (Unknown size)
.................done: 766,976 bytes
49 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions
Enable per request file info about files used from the APC cache [no] :
Enable spin locks (EXPERIMENTAL) [no] :
building in /var/tmp/pear-build-root/APC-3.1.6
running: /tmp/pear/temp/APC/configure --enable-apc-filehits=no --enable-apc-spinlocks=no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20090626
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable APC support... yes, shared
checking whether we should enable cache request file info... no
checking whether we should use mmap... yes
checking whether we should use semaphore locking instead of fcntl... no
checking whether we should use pthread mutex locking... yes
pthread mutex's are supported!
checking whether we should use spin locks... no
checking whether we should enable memory protection... no
checking for zend_set_lookup_function_hook... no
checking for sigaction... yes
checking for union semun... no
checking whether we should enable valgrind support... checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
yes
checking valgrind/memcheck.h usability... no
checking valgrind/memcheck.h presence... no
checking for valgrind/memcheck.h... no
checking for shm_open in -lrt... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc.c -o apc.lo
mkdir .libs
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc.c  -fPIC -DPIC -o .libs/apc.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/php_apc.c -o php_apc.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/php_apc.c  -fPIC -DPIC -o .libs/php_apc.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_cache.c -o apc_cache.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_cache.c  -fPIC -DPIC -o .libs/apc_cache.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_compile.c -o apc_compile.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_compile.c  -fPIC -DPIC -o .libs/apc_compile.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_debug.c -o apc_debug.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_debug.c  -fPIC -DPIC -o .libs/apc_debug.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_fcntl.c -o apc_fcntl.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_fcntl.c  -fPIC -DPIC -o .libs/apc_fcntl.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_main.c -o apc_main.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_main.c  -fPIC -DPIC -o .libs/apc_main.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_mmap.c -o apc_mmap.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_mmap.c  -fPIC -DPIC -o .libs/apc_mmap.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_sem.c -o apc_sem.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_sem.c  -fPIC -DPIC -o .libs/apc_sem.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_shm.c -o apc_shm.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_shm.c  -fPIC -DPIC -o .libs/apc_shm.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_pthreadmutex.c -o apc_pthreadmutex.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_pthreadmutex.c  -fPIC -DPIC -o .libs/apc_pthreadmutex.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_spin.c -o apc_spin.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_spin.c  -fPIC -DPIC -o .libs/apc_spin.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/pgsql_s_lock.c -o pgsql_s_lock.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/pgsql_s_lock.c  -fPIC -DPIC -o .libs/pgsql_s_lock.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_sma.c -o apc_sma.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_sma.c  -fPIC -DPIC -o .libs/apc_sma.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_stack.c -o apc_stack.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_stack.c  -fPIC -DPIC -o .libs/apc_stack.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_zend.c -o apc_zend.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_zend.c  -fPIC -DPIC -o .libs/apc_zend.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_rfc1867.c -o apc_rfc1867.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_rfc1867.c  -fPIC -DPIC -o .libs/apc_rfc1867.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_signal.c -o apc_signal.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_signal.c  -fPIC -DPIC -o .libs/apc_signal.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_pool.c -o apc_pool.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_pool.c  -fPIC -DPIC -o .libs/apc_pool.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_iterator.c -o apc_iterator.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_iterator.c  -fPIC -DPIC -o .libs/apc_iterator.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_bin.c -o apc_bin.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_bin.c  -fPIC -DPIC -o .libs/apc_bin.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=compile cc  -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/APC/apc_string.c -o apc_string.lo
 cc -I. -I/tmp/pear/temp/APC -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/APC/apc_string.c  -fPIC -DPIC -o .libs/apc_string.o
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/APC-3.1.6/include -I/var/tmp/pear-build-root/APC-3.1.6/main -I/tmp/pear/temp/APC -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o apc.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/APC-3.1.6/modules  apc.lo php_apc.lo apc_cache.lo apc_compile.lo apc_debug.lo apc_fcntl.lo apc_main.lo apc_mmap.lo apc_sem.lo apc_shm.lo apc_pthreadmutex.lo apc_spin.lo pgsql_s_lock.lo apc_sma.lo apc_stack.lo apc_zend.lo apc_rfc1867.lo apc_signal.lo apc_pool.lo apc_iterator.lo apc_bin.lo apc_string.lo -lrt
cc -shared  .libs/apc.o .libs/php_apc.o .libs/apc_cache.o .libs/apc_compile.o .libs/apc_debug.o .libs/apc_fcntl.o .libs/apc_main.o .libs/apc_mmap.o .libs/apc_sem.o .libs/apc_shm.o .libs/apc_pthreadmutex.o .libs/apc_spin.o .libs/pgsql_s_lock.o .libs/apc_sma.o .libs/apc_stack.o .libs/apc_zend.o .libs/apc_rfc1867.o .libs/apc_signal.o .libs/apc_pool.o .libs/apc_iterator.o .libs/apc_bin.o .libs/apc_string.o  -lrt  -Wl,-soname -Wl,apc.so -o .libs/apc.so
creating apc.la
(cd .libs && rm -f apc.la && ln -s ../apc.la apc.la)
/bin/bash /var/tmp/pear-build-root/APC-3.1.6/libtool --mode=install cp ./apc.la /var/tmp/pear-build-root/APC-3.1.6/modules
cp ./.libs/apc.so /var/tmp/pear-build-root/APC-3.1.6/modules/apc.so
cp ./.libs/apc.lai /var/tmp/pear-build-root/APC-3.1.6/modules/apc.la
PATH="$PATH:/sbin" ldconfig -n /var/tmp/pear-build-root/APC-3.1.6/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /var/tmp/pear-build-root/APC-3.1.6/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-APC-3.1.6" install
Installing shared extensions:     /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib/php/extensions/no-debug-non-zts-20090626/
running: find "/var/tmp/pear-build-root/install-APC-3.1.6" | xargs ls -dils
3935384   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6
3936266   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr
3936267   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local
3936268   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib
3936269   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib/php
3936270   4 drwxr-xr-x 3 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib/php/extensions
3936271   4 drwxr-xr-x 2 root root   4096 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib/php/extensions/no-debug-non-zts-20090626
3936265 648 -rwxr-xr-x 1 root root 661620 2011-02-02 22:44 /var/tmp/pear-build-root/install-APC-3.1.6/usr/local/lib/php/extensions/no-debug-non-zts-20090626/apc.so

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/apc.so'
install ok: channel://pecl.php.net/APC-3.1.6
configuration option "php_ini" is not set to php.ini location
You should add "extension=apc.so" to php.ini
bash#

To avoid having to manually add the apc.so extension to your php.ini, execute these commands first:

bash# pear config-set php_ini /etc/php5/apache2/php.ini
bash# pecl config-set php_ini /etc/php5/apache2/php.ini

And now restart Apache for the changes to take effect:

bash# sudo apache2ctl graceful

Timing your scripts

Monday, February 1st, 2010
$start_time = microtime(true);
<...insert code to time here...>
$stop_time = microtime(true);
$time_diff = $stop_time - $start_time;
echo "Script took $time_diff seconds to execute";

IE bug: text disappearing randomly behind a picture

Wednesday, January 20th, 2010

Even though the text had a high z-index, it would disappear after few seconds behind the picture it’s supposed to be on, or when you switch to another Windows application then come back on the browser.

This erratic behavior turned out to be when IE doesn’t have a Doctype declared.

CakePHP doesn’t define any Doctype by default, so you need to edit your default layout and include it.

In CakePHP 1.1: edit app/views/layout/default.hthml

In CakePHP 1.1: edit app/views/layout/default.ctp

and add:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

… at the very top, before the html tag.

This happens not even on an old IE6, but on IE8 itself.

Increasing PHP limits

Tuesday, September 2nd, 2008

When doing statistical computations on a DB, you can easily reach the default memory and execution time limits of PHP.

You could change those settings directly in your php.ini file, but it would make the changes server-wide, meaning that even those scripts that should never eat that much memory can potentially hog the system if they start running wild.
It’s better to enable it on a file basis, if not on a compute-heavy function basis using ini_set.

For instance if your script reaches the default 16M of memory usage, this message will appear:

PHP error: Fatal error: Allowed memory size of 16777216 bytes exhausted

To change the default value:

ini_set('memory_limit', '20M');

When reaching the maximum execution time of a script you’ll get this message:

Maximum execution time of 30 seconds exceeded

To change the default value:

ini_set('max_execution_time', 90);

When dealing with extremely long processes, like for instance sending millions of notifications to your app users on Facebook, you might even want to use as much memory and time as possible:

ini_set('memory_limit','900M');
ini_set('max_execution_time', 90000);
ini_set('display_errors', 1);