Using SimpleChannelServer to manage a PEAR channel on Google Code

December 8th, 2008 by bbieber Leave a reply »

I needed to build a quick pear channel for a library I had built – here’s all it takes:

For this example, we’ll assume your Google project is named: myproject

First, we need to check out the root of your Google Code project, so we can place the channel files here, away from your source code files.

svn checkout https://myproject.googlecode.com/svn/ myproject --username mygoogleusername

Now that we have a checkout, let’s build the channel:

cd myproject

Download the SimpleChannelServer phar file from here:

wget "http://svn.php.net/viewvc/pear2/sandbox/SimpleChannelServer/trunk/pearscs.phar?view=co" -O pearscs.phar

Using a recent version of PHP 5.3, let’s execute the pearscs.phar file, and create the channel for the project:

php pearscs.phar create myproject.googlecode.com/svn myproject

Now commit the files to your repository, and let’s try discovering your pear channel.

pear channel-discover myproject.googlecode.com/svn/

You should see the following message, telling you that the channel was added successfully:

Adding Channel "myproject.googlecode.com/svn" succeeded
Discovery of channel "myproject.googlecode.com/svn/" succeeded

Now let’s create our pear package. PEAR has many tools available to aid in package creation. To get up and running quickly, we’ll start from an example and modify it for our own needs.
Download http://simplecas.googlecode.com/svn/trunk/makepackage.php and save it to your local project as trunk/makepackage.php

Modify this file to use your channel name, package name, release information and maintainer info.
Now let’s create the package:

php makepackage.php
pear package

Now you should have a file myproject-0.1.0.tgz

Let’s release the package to the world, substitute the lead name with your handle:

php pearscs.phar release trunk/myproject-0.1.0.tgz leadhandle

This will add the distribution files to the /get/ directory, and update the channel xml files. There’s a small issue with using Google code to host the xml files, and that’s that the content-type needs to be sent as application/xml or text/xml for the channel files to be read correctly, so set the mime-type property for the xml files.

find . -name '*.xml' | xargs svn propset svn:mime-type application/xml

Now commit these files to your repository, and let’s try installing the package!

pear install myproject/myproject-0.1.0

If everything went correctly, pear should have installed the package. Now when you create a new release, just run the release command, update the mime-type on the xml files and commit your changes.

FYI – the package I needed a channel for is SimpleCAS a PHP5 library for authenticating users against a JA-SIG Central Authentication Service.

Updates

There are a couple gotchas for phar packaging. Here’s some info that might ease some problems with creating or opening phars or PEAR packages:
* Make sure you have zlib! ./configure –with-zlib
* php.ini settings

[phar]
phar.readonly = 0
phar.require_hash = 0
Advertisement

9 comments

  1. Amir says:

    Fantastic!
    Many thanks for all the hard work you have put on SimpleChannelServer.

  2. David Coallier says:

    Well done boi :) Very good work, glad you are with PEAR :D Keep going you are doing very well

  3. Brett says:

    Just as an update, if you receive a message like – Fatal error: Cannot use string offset as an array in /usr/local/lib/php/PEAR/REST/10.php
    This means an xml file served out by the channel does not have text/xml or application/xml as the content type. Remember to re-run find . -name ‘*.xml’ | xargs svn propset svn:mime-type application/xml when you release a new package.

  4. Got some errors:

    [17-Mar-2010 03:09:43] PHP Warning: Zend Monitor UI is disabled in CLI/CGI run… in Unknown on line 0
    [17-Mar-2010 00:09:43] PHP Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in C:\Program Files (x86)\Zend\Apache2\htdocs\habrahabr\pearscs.phar on line 25
    [17-Mar-2010 00:09:43] PHP Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in C:\Program Files (x86)\Zend\Apache2\htdocs\habrahabr\pearscs.phar on line 25
    [17-Mar-2010 00:09:43] PHP Parse error: syntax error, unexpected T_STRING in C:\Program Files (x86)\Zend\Apache2\htdocs\habrahabr\pearscs.phar on line 25

  5. C:\>php -v
    PHP 5.2.11 (cli) (built: Nov 8 2009 15:10:54)

    Maybe it’s explain my problem =)

  6. Brett says:

    Yep. The \ is the namespace separator. You’ll need PHP >= 5.3

  7. Channel was created and uploaded to Google Code but I got such errors during channel-discover (errors descriptions are from “pear update-channels” but it doent metters, descriptions are the same):

    Updating channel “habrahabr.googlecode.com/svn”
    Channel “habrahabr.googlecode.com/svn” is not responding over http://, failed with message: File http://habrahabr.googlecode.com:80/svn/channel.xml not valid (received: HTTP/1.1 404 Not Found
    )
    Trying channel “habrahabr.googlecode.com/svn” over https:// instead
    Cannot retrieve channel.xml for channel “habrahabr.googlecode.com/svn” (File https://habrahabr.googlecode.com:443/svn/channel.xml not valid (received: HTTP/1.1 404 Not Found
    ))

    Used PEAR 1.7.2 & 1.9.0; It wery strange ‘couse channel.xml files are availbe =\

  8. bbieber says:

    Hi Alexander,

    It looks like the channel file is there, but the xml file doesn’t have the correct content type. FTA –

    “There’s a small issue with using Google code to host the xml files, and that’s that the content-type needs to be sent as application/xml or text/xml for the channel files to be read correctly, so set the mime-type property for the xml files.”

    You’ll have to run this for all the xml files:
    svn propset svn:mime-type application/xml channel.xml

    I’m not sure how to set that for all the xml files with Windows. On linux/unix we’d just do:
    find . -name ‘*.xml’ | xargs svn propset svn:mime-type application/xml

    Set those properties, commit the files, and you should be good to go.

Leave a Reply