[Xapian-discuss] PHP bindings

Francis Irving francis at flourish.org
Mon Oct 2 18:48:27 BST 2006

On Mon, Oct 02, 2006 at 12:32:12PM +0100, Olly Betts wrote:
> Currently the PHP4 bindings use a SWIG option which flattens the
> object interface into a series of functions, so you have to write:
>   $database = new_Database("mydb");
>   echo Database_get_doccount($database) . " documents\n";
> instead of the more natural:
>   $database = new Database("mydb");
>   echo $database->get_doccount() . " documents\n";
> While object creation is OK, I find actually using objects is much
> clumsier under the flat function approach.

> The reason we do this is because SWIG's support for the later style was
> broken.  This has now been fixed, so I'm wondering if we should switch
> to using this.  The upside is that the PHP4 Xapian API is more natural.
> The downside is that existing code will need adapting.

The related thing that I would like fixing is the way the Xapian
function contaminate the global "namespace" (in as much as PHP4 or
PHP5 have namespaces!). Other PHP libraries use a prefix on functions.
Xapian could use xapian_ or maybe just xap_. 

So, for example, I'm suggesting:
    $database = new xapian_Database("mydb");
Which obviously adds fewer extra prefixes when using the object
oriented interface that you suggest, as you only need it for the
object construction functions.

IIRC, I had to rename at least one of our functions because it
clashed with a Xapian one with quite a general name (like 'Database').
> So if you use the Xapian bindings under PHP4 (not PHP5!), do you think
> the pain of updating your code is worth the gain from the more OO-like
> API?  If there was a simple script which did most of the work of
> updating your scripts, would that change your opinion?

I think all the places we call Xapian from PHP are in one file, so it
wouldn't be too bad. 


The easiest helpful thing would probably be a script which checked for
old Xapian functions and give a warning. i.e. Just greps a PHP file
for old style functions. Then I could run it against our PHP files,
and update them by hand until it gives no warnings.
Upgrading Xapian version is already daunting due to database changes -
would really want two version of Xapian installed at once on our
server, but I'm not confident how to do that with all their bindings.
So I'm waiting before upgrading Xapian, until at least Flint is
completely stable (is it yet?), as we may as well migrate to that at
the same time.

On Mon, Oct 02, 2006 at 01:53:03PM +0100, Olly Betts wrote:
> Also, PHP5 seems to be significantly better than PHP4 in a number of
> ways, and my impression is that PHP5 adoption has reached critical mass.
> I think PHP4's days are numbered at this point.

We've not seen a good reason to even consider PHP5 yet. 

I can see lots of stuff making it more like better designed
programming languages. 
However it is all things we have already worked round. It looks
to me like an attempt by Zend to move into PHP/Perl territory,
rather than playing to PHPs strengths.

Are there any performance benefits? For example, it still doesn't seem
to cache compiled bytecode.


More information about the Xapian-discuss mailing list