Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47818 invoked by uid 1010); 28 Feb 2005 15:20:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 47803 invoked from network); 28 Feb 2005 15:20:11 -0000 Received: from unknown (HELO akbkhome.com) (127.0.0.1) by localhost with SMTP; 28 Feb 2005 15:20:11 -0000 X-Host-Fingerprint: 202.81.246.113 246-113.netfront.net Received: from ([202.81.246.113:33078] helo=newweb.akbkhome.com) by pb1.pair.com (ecelerity HEAD r(5124)) with SMTP id 39/33-43672-9A633224 for ; Mon, 28 Feb 2005 10:20:10 -0500 Received: from [192.168.0.184] (helo=[192.168.0.184]) by newweb.akbkhome.com with esmtp (Exim 4.44) id 1D5mnE-0001gu-98; Mon, 28 Feb 2005 23:26:45 +0800 Message-ID: <42233717.9050107@akbkhome.com> Date: Mon, 28 Feb 2005 23:21:59 +0800 User-Agent: Mozilla Thunderbird 0.8 (X11/20040926) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bob Beaty CC: internals@lists.php.net References: <2005022807371112877%drbob@TheManFromSPUDcom> In-Reply-To: <2005022807371112877%drbob@TheManFromSPUDcom> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ACL-Warn: "cleared badlog" Subject: Re: [PHP-DEV] How to embed PHP5 into multi-threaded C app? From: alan@akbkhome.com (Alan Knowles) these still need tidying up alot, but the do work. http://docs.akbkhome.com/php_embed.c.txt http://docs.akbkhome.com/php_embed.h.txt replace the code in php_embed with them, make sure you compile with the zts enabled, and the macros's are similar to the original embed (use threaded start call at application start up, and thread start /start end within the pthread_start(...callback..) method check out php.pecl on #efnet you might get lucky.. Regards Alan Bob Beaty wrote: > All, > I've searched the web for this answer and I'm stumped. I can't find > the answers. So I thought I'd try the lists. Here goes: > I have seen how to embed PHP 5 using the code like: > > ... > php_embed_module.ub_write = my_ub_write_func; > php_embed_module.log_message = my_log_func; > php_embed_module.sapi_error = my_error_log; > ... > zend_eval_string(...); > ... > > And from this, I looked in the code to see that php_embed_module is a > static variable that's used in the initialization methods so it > *seems* as though this can't possibly be thread-safe. > Yet web servers do it all the time. > I read on the web that the global variables for the PHP engine are > maintained in the thread where they were originally defined. This > leads me to believe that there's the possibility that the > php_embed_module and other important variables might be thread-local > storage, and therefore thread-safe. > Yet if that were the case, how does one define different write, log, > and error functions so that the engine of one thread does not > interfere with another? > > In general, my problem is this: > I have a multi-threaded C++ app that I want to embed the PHP 5 engine > into. I have read up how to create extensions to PHP, and will do that > as necessary, but I need to be able to call this engine from my code > and capture stdout, stderr, etc. > Can I do this with PHP 5.0.3 as it exists now? > Are there special things I need to watch out for? > Any pointers, FAQ sites, etc. that I can look at would be most helpful.