PHP

Using Growl to tail a log file

Mikey_p from the Portland Drupal Group pointed me towards a blog post he'd done on using Growl to watch for PHP errors. Always looking to put my fingerprints on something I decided to do the same but using PHP rather than Python.

The short version is install growlnotify then run the following from the terminal:

tail -n 0 -f ~/Sites/nm/logs/access_log | php -r 'while ($m = fgets(STDIN)) shell_exec("growlnotify -p 0 AlertTitle -m ". escapeshellarg($m));'
Obviously you'll need to use the right filename and change AlertTitle to something more to your liking.

Getting PHP + GD working on Leopard (aka recompiling everything)

Here's my writeup on how to recompile PHP for Leopard to get GD working. The basic plan is recompile Apache and PHP from source. It may totally bork your system, I'm just writing it down so the next time I need to do this I can remember what I did. I wish I could give credit to all the places I stole bits from but I didn't do a good job of keeping notes early on.

Using SimpleXML with HTML

PHP 5's SimpleXML module is one of the the biggest reasons to upgrade to 5. If you're parsing RSS feeds or the results of webservice requests it works beautifully and saves a ton of time. The only problem with it is that it'll only load valid XML. I banged my head against it for way to long before coming up with the following:

<?php
  $doc
= new DOMDocument();
 
$doc->strictErrorChecking = FALSE;
 
$doc->loadHTML($html);
 
$xml = simplexml_import_dom($doc);
?>

Using PHP and CURL to do an HTML file POST

After scouring the internet to find out how to do multipart post operations and finding nothing nothing, I decided to save someone else some time. The trick is that @ before the file name:

<?php
$fullflepath
= 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
 
'photo'=>"@$fullfilepath",
 
'title'=>$title
);       

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
?>

Originally posted here: http://drewish.com/blogger/archives/2005/01/27/using_php_and_curl_to_do_...

PHP One-liners

I'm starting a collection of one-line PHP programs that I've used on the command line.

This removes trailing white space from a DOS file:

C:\>php -r "foreach (file($argv[1]) as $l) {print rtrim($l).chr(13).chr(10);}" user.module > user.module.trimed

This little gem escapes code for inclusion in HTML. The invocation uses UNIX's cat utility, on Widows you could use type:

$ cat test.php | php -r "print htmlentities(file_get_contents('php://stdin'));"

Installing PHP 5 on Windows

This page provides instructions for a Drupal developer who'd like to install PHP 5 on their desktop computer. The instructions assume that you're running a recent version of Windows (NT, 2000, XP, or 2003). Older version like Windows 95, 98 and Me will not be addressed.

Enabling PHP Modules

Phlickr uses two several of PHP5's extensions, CURL and SimpleXML. In some cases these two extensions may not be enabled by default.

The first step is verify that the modules are not already being loaded. You view a list of the modules using the following command:

Downloading Democracy Now! automatically

Here's a PHP script I wrote for the radio station to download each day's copy of Democracy Now!. This requires that the PHP cURL extension be installed.

Setup Drupal 5

The station's website will be build using Drupal an extremely powerful, open source content managment system written in PHP.

Drupal uses some PHP functions that require the installation of additional ports. You'll need:

  • devel/php5-pcre - Perl regular expressions.
  • textproc/php5-xml - XML parsing.
  • databases/php5-mysqli - MySQL support for PHP.
  • www/php5-session - Session support.
  • graphics/php5-gd - Image handing. Optional, some modules need it.
  • converters/php5-mbstring - Unicode support. Optional, but Drupal prefers that it be installed.

Uploading a photo

This sample shows how to upload all the JPG files in a directory to Flickr. Take a look at the PhlickrUploader script listed on the tools page for a more complete uploading example.

FAQ

Q: Does Phlickr work with PHP4?
A: No, [[Phlickr]] uses several of the new features in PHP5. You'll need to try one of the [[other PHP projects]], most are compatible with PHP4.
Q: Can you recommend a PHP5 web host

Phlickr

Phlickr is an open source PHP5 based api kit used to access the Flickr API.

I co-authored the book Building Flickr Applications with PHP published Apress.

for you, a photo

andy x dustin

ads

User login

Syndicate content