Skip to main content.
home | support | download

Back to List Archive

RE: Anyone using the PHP module?

From: Patrick O'Lone <polone(at)>
Date: Fri Oct 10 2003 - 20:51:46 GMT

> I don't know a think about PHP.  What's a "resource" vs. and 
> object in PHP?

Well, a "PHP" resource is a handle to the "real" resource that would be
created using the native C function. For example, in the SWISH-E C API,


would return SW_HANDLE. Obviously, the PHP scripting language doesn't know
what this is. What we do instead is register that SW_HANDLE as a resource in
PHP and return a handle instance of that, so:

static int le_swishe;

	SW_HANDLE hSwishe;
	char *szIndexList = NULL;
	int nLength = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&szIndexList, &nLength)
		== FAILURE) {



	hSwishe = SwishInit(szIndexList);
	if (hSwishe) {
		ZEND_REGISTER_RESOURCE(return_value, swishe, le_swishe);

	} else {



This is the PHP C glue that would wrap the SwishInit() function for use in
PHP. With this, the PHP code to get a SWISH-E handle is:


$hSwishe = swishe_init("index1 index2");
if (is_resource($hSwishe)) {

	echo "Got a SWISH-E handle!";

} else {

	echo "Unable to load SWISH-E!";


The current implementation currently gives me back an object, as follows:


$oSwishe = swish_open("index1");
if (is_object($oSwishe)) {

	echo "Got a SWISH-E object!";

} else {

	echo "Object instantiation failed!";



and all API calls are methods of objects, not raw function calls.

> I wouldn't use efree() externally, and instead use the API.  
> For example, to free a search object (search_close above) I 
> it should use
>   Free_Search_Object( search );
> calling efree() directly would cause a memory leak.  For 
> example, inside the search structure is the query string, 
> sort parameters and -L limit parameters.

He has to use efree() which is a PHP memory deallocation routine that wraps
free(). The efree() routine performs memory management and prevents memory
leaks from occuring. Of course, you might be referring to native calls to
malloc() within the SWISH-E internals that would get messed up with calls to
PHP's emalloc() and efree() routines. 
> > 
> > Is there going to be a SWISH-E API for indexing as well?
> Considering that indexing is a single command operation, I 
> don't really see where an API would help.  That's what 
> "system()" is for.

Well, I'm talking about an API where I could open an index and supply my own
XML document, something like:

hIndex = swishe_index_open("index", "swish-e.conf");
swishe_index_capture(hIndex, "<?xml

Basically, the API would allow my application to provide the text to the
indexing engine directly and allow me to supply documents by "writing" to
the indexer inside my application, avoiding exec() or system(). This allows
an application developer to more tightly integrate SWISH-E's powerful search

If you have questions, comments, or suggestions about the aforementioned
message, you can respond by replying to this message or contacting us at
(309)-743-0800. Thank you.


Patrick O'Lone
Software Project Manager

Received on Fri Oct 10 20:55:32 2003