Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

11 Mar 2011

Compress PHP file

Use PHP itself to compress a PHP source file.

This command line option will strip all comments and white space.
php –w input.php > output.php

10 Mar 2011

Check request is via AJAX in PHP

A simple function to indicate whether a request was made via AJAX or not (note: this is easily spoofed so it's not a secure method).
function isAjax() 
{
   return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) 
   && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

7 Mar 2011

Retrieving MySQL enum values in PHP

Retrieve an array of all the available enum values.
if ($result = mysql_query("SHOW COLUMNS FROM {$table} LIKE '{$column}'))
{
  $enum = mysql_fetch_object($result);
  preg_match_all("/'([\w ]*)'/", $enum->Type, $values);
}

4 Mar 2011

How to use locks in PHP cron jobs to avoid cron overlaps

Cron jobs are hidden building blocks for most of the websites. They are generally used to process/aggregate data in the background. However as a website starts to grow and there is gigabytes of data to be processed by every cron job, chances are that our cron jobs might overlap and possibly corrupt our data. In this blog post, I will demonstrate how can we avoid such overlaps by using simple locking techniques. I will also discuss a few edge cases we need to consider while using locks to avoid overlap.
http://abhinavsingh.com/blog/2009/12/how-to-use-locks-in-php-cron-jobs-to-avoid-cron-overlaps/

3 Mar 2011

Develop PHP applications with Picasa Web Albums


Integrate data from Picasa Web Albums into a custom PHP application
Picasa Web Albums offers Web application developers a REST-based Data API to manipulate the photos and albums stored on its servers. PHP's SimpleXML extension and Zend's GData Library are ideal to process the XML feeds generated by this API so you can customize PHP photo management and photo sharing applications. In this article, meet the Picasa Web Albums Data API and see how you can use it to retrieve photos and photo metadata; add, modify and delete photos; and perform keyword searches of Picasa's user-generated content.
http://www.ibm.com/developerworks/library/x-picasalbum/

28 Feb 2011

Search and update Google Base with PHP


Use PHP to process and integrate data from Google Base with a custom Web application
Google Base allows users to store any type of content online in Google's version of a massive online database. Web application developers are able to access and search this content through the Google Base Data API. This article introduces the Google Base Data API and demonstrates it in the context of a PHP application, explaining how to use SimpleXML and the Zend_Gdata module to search, retrieve, add, and edit different types of data on Google Base.
http://www.ibm.com/developerworks/library/x-gbase/