Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107821 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23271 invoked from network); 18 Nov 2019 17:02:48 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Nov 2019 17:02:48 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id DBA822C84C2 for ; Mon, 18 Nov 2019 06:55:28 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20773 94.136.40.0/24 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mailex.mailcore.me (mailex.mailcore.me [94.136.40.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 18 Nov 2019 06:55:28 -0800 (PST) Received: from cpc81936-leic18-2-0-cust70.8-1.cable.virginm.net ([82.6.254.71] helo=[192.168.0.11]) by smtp03.mailcore.me with esmtpa (Exim 4.92.3) (envelope-from ) id 1iWiR5-0001xg-47 for internals@lists.php.net; Mon, 18 Nov 2019 14:55:27 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Message-ID: <64F0D442-F781-4895-BAD4-9ED74DF96E73@saxonica.com> Date: Mon, 18 Nov 2019 14:55:26 +0000 To: PHP internals X-Mailer: Apple Mail (2.3445.104.11) X-Mailcore-Auth: 439400269 X-Mailcore-Domain: 1881035 X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Status: not scanned, license restriction X-KLMS-AntiPhishing: not scanned, license restriction X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2019/11/18 08:29:00 #10777515 X-KLMS-AntiVirus-Status: Clean, skipped X-Envelope-From: Subject: Saxon/C - PHP C++ extension threading issues From: oneil@saxonica.com (O'Neil Delpratt) Hi, Consultancy help: I have written an PHP 7.X extension to my Saxon/C C++ API. My C++ = program has an Excelsior JET JNI environment which is created as a = static variable at the start of the program and released at the end. The threads are created by the JET Runtime, e.g. GC thread, weak = reference handler thread, finalizers thread, etc. Initially I thought = best to create the Jet runtime for each request, but this did not work. = So I tried to keep the Jet runtime alive for the lifetime of the = extension, which could be reused between requests. I create the JET runtime (which has several threads) in the = PHP_MINIT_FUNCTION(saxonc) To make sure the clean up of the JET threads happens I have added a = release method in the MSHUTDOWN_FUNCTION of the PHP extension. The problem is when I run the PHP extension in the browser it just = hangs. If I remove the code to manage the JET threads the PHP scripts = run, but does not kill the JET threads. The only way to kill the = threads. How can I manage these resources between requests? Is there a way to = keep a global variable to the JET resources that maintains the static = variable from the C++ code between requests? Somehow I think the management via globals as discussed in your blog: = http://blog.jpauli.tech/2017-01-12-threads-and-php-html/ is relevant and = I have tried to follow through with this in some test code to get things = working, but still not resolved the issue. Here is snippet of the my C++ code for the PHP extension: void php_saxonc_initialize(void){ =20 if(SaxonProcessor::jvmCreatedCPP =3D=3D 0){ =20 SaxonProcessor::jvmCreatedCPP=3D1; =20 SaxonProcessor::sxn_environ=3D (sxnc_environment = *)malloc(sizeof(sxnc_environment)); =20 /* * First of all, load required component. * By the time of JET initialization, all components should be = loaded. */ =20 SaxonProcessor::sxn_environ->myDllHandle =3D loadDefaultDll (); =20 /* * Initialize JET run-time. * The handle of loaded component is used to retrieve Invocation = API. */ initDefaultJavaRT=20 (SaxonProcessor::sxn_environ); =20 =20 } } PHP_MINIT_FUNCTION (saxon) { php_saxonc_initialize (); zend_class_entry ce ; INIT_CLASS_ENTRY (ce, "SaxonProcessor", SaxonProcessor_methods); =20 .... In a different approach I tried calling the php_saxonc_initialize() = method in the 'static PHP_GINIT_FUNCTION(saxon)=E2=80=99 but still did = not get it to work. This is linked to this bug issue: https://saxonica.plan.io/issues/2055 Full source code for the PHP extension Saxon/C: = https://dev.saxonica.com/repos/archive/opensource/latest9.9/hec/Saxon.C.AP= I/php7_saxon.cpp = https://dev.saxonica.com/repos/archive/opensource/latest9.9/hec/Saxon.C.AP= I/php_saxon.h I am wondering if someone could assist me and collaborate to resolve it. = We are willing to pay for the consultancy work. kind regards, O'Neil=