Sara,

Sorry if the question was answered before, I will try to look harder next
time.

Just for the record:

- I ended up doing what you suggested but in MINIT. Given the facts you
provided, I'll change it to RINIT.

- The php_mysql.h file doesn't include the constants for the resource name,
so I defined a constant in my own code.

- The php_mysql_conn type is not defined in the .h file, so it was also
replicated.

You're again right about the inclusion of the function in Appendix A, I was
worried if this usage was "correct" enough.
Again, thank you all very much for your work and specially to you Sara for
sharing your knowledge.

Regards,
Mauro.

> -----Original Message-----
> From: Sara Golemon [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, November 30, 2006 3:42 AM
> To: Mauro N. Infantino
> Cc: internals@lists.php.net
> Subject: [PHP-DEV] Re: Cross-extension resource
> 
> Surprising how often this question comes up....
> 
> /* True global to store local copy of mysql's le_link */
> static int local_mysql_le = -1;
> 
> PHP_RINIT_FUNCTION(myext)
> {
>      if (local_mysql_le == -1) {
>          local_mysql_le = zend_fetch_list_dtor_id("mysql link");
>      }
> 
>      return SUCCESS;
> }
> 
> A few notes about this solution:
> (1) I'm doing this in RINIT because, prior to PHP 5.1, 
> there's no way to 
> enforce load order for shared extensions, so it's possible 
> that your ext 
> will load prior to mysql and therefore the list ID won't have been 
> registered during the time of MINIT.  If you know that MySQL 
> will always 
> be loaded prior to your extension (either because of local policy or 
> because you're only targeting 5.1 or later -- which has module 
> dependencies), then you can do it once in MINIT and be done with it.
> 
> (2) The name "mysql link" is case sensitive and must match 
> the resource 
> type name you're looking for precisely.  There's also no 
> guard against 
> the (unlikely) possibility that some other extension registers a 
> resource named "mysql link" which isn't actually a MySQL link.
> 
> (3) You should guard against the possibility that no matching list id 
> will be found for that name (perhaps MySQL isn't loaded), so 
> be sure to 
> put some error checking in there...  Hint: This function returns 0 on 
> failure.
> 
> (4) You'll probably need to fetch "mysql link persistent" as well...
> 
> I think this function is covered in Appendix A, but the cat 
> is on my lap 
> and I can't reach the bookshelf from here....
> 
> -Sara

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to