📄 quercus.xtp
字号:
$session = $request->getSession(true); $foo = $session->getAttribute("foo");?></example></s2><s2 title="Using META-INF/services to package Quercus extensions in jar files"><p>At startup time Quercus discovers and uses files within the META-INF/servicesto discover modules and classes that are made available within the PHPenvironment.</p><s3 title="META-INF/services/com.caucho.quercus.QuercusModule"><p><code>META-INF/services/com.caucho.quercus.QuercusModule</code>contains a list of classes that are modules. Each public member of amodule becomes available as a top-level PHP function.</p><p>For example a line like:</p><example title="META-INF/services/com.caucho.quercus.QuercusModule">...com.caucho.quercus.lib.date.DateModule...</example><p>references the java class:</p><example title="com/caucho/quercus/lib/date/DateModule.java">package com.caucho.quercus.lib.date.DateModulepublic class DateModule extends AbstractQuercusModule{ ... public static final int CAL_GREGORIAN = 0; ... public static int cal_days_in_month(int cal, int month, int year) { ... } ...}</example><p>When Quercus starts, the DateModule class is automaticallyintrospected, and a PHP script can call the function defined in themodule:</p><example title="Calling the cal_days_in_month function"><?php$var = cal_days_in_month(CAL_GREGORIAN, 2, 2000)?></example></s3><s3 title="META-INF/services/com.caucho.quercus.QuercusClass"><p><code>META-INF/services/com.caucho.quercus.QuercusClass</code>contains a list of classes that should become available to PHP asobjects.</p><p>For example a line like:</p><example title="META-INF/services/com.caucho.quercus.QuercuClass">...com.caucho.quercus.lib.date.DateTime...</example><p>references the java class:</p><example title="com/caucho/quercus/lib/date/DateTime.java">package com.caucho.quercus.lib.date;public class DateTime{ public static final String ISO8601 = "Y-m-d\\TH:i:sO"; public DateTime(String timeString) { ... } ... public String format(String format) { ... } ...}</example><p>When Quercus starts, the DateTime class is automaticallyintrospected, and a PHP script can instantiate and use the object:</p><example title="Using the DateTime class in PHP"><?php$var = new DateTime("last week");echo $a->format(DateTime::ISO8601);?></example></s3></s2></s1> <!-- java integration --><s1 name="module_highlights" title="PHP Module highlights"><s2 name="standard_modules" title="Standard modules"><p>Quercus implements the standard PHP libraries (arrays, strings,date, regexp, etc). It also supports extension libraries like zip andzlib for compression, mcrypt for encryption, mail (implemented withJavaMail), and bcmath for large numbers.</p></s2><s2 name="apc_module" title="APC (object caching)"><p>For PHP object caching, Quercus implements the APC module. PHP applicationscan use the APC functions to save PHP objects without resorting toserialization and database persistence. Because Quercus runs in Resin,a Java web server, the saved objects are quickly available to anythread running PHP. In other words, unlike Apache which makes sharing acrossdifferent PHP processes difficult, Quercus can just store a singleton cacheof the APC-cached objects.</p><p>Because Quercus compiles PHP to Java code, PHP scripts get the opcodecaching of APC for free. At this time, performance of Quercus is roughtlycomparable with performance of mod_php with APC, i.e. it is significantlyfaster (3-5 times) than mod_php running by itself.</p></s2><s2 name="gd_module" title="Image support ('gd')"><p>Quercus provides the image module, so users can use image manipulationfunctions like watermarking and thumbnail generation inany PHP script on Quercus. .jpg, .png, and .gif files are currentlysupported. Java users will also find these libraries convenient.</p></s2><s2 name="pdflib_module" title="PDF generation (PDFlib api)"><p>PDF generation in Quercus follows the PDFlib API. Since the QuercusPDF implementation is a new implementation in Java, no special downloadsare needed to use PDF.</p></s2><s2 name="json_module" title="AJAX (JSON)"><p>Quercus also includes the JSON module for encoding and decodingAJAX-style requests. The JSON modules is an excellent example ofthe benefits of writing modules in Java. Because Java supportsgarbage collection and protects from pointer overruns, the JSON moduleimplementation is straightforward and reliable, without having to worryabout all the possible memory problem in a C library.</p></s2><s2 name="gettext_module" title="Gettext (localization)"><p>Quercus supports the gettext API and .po and .mo files.gettext is a portable API for localization, i.e. translation of programmessages. In the future, the Quercus gettext implementation willsupport Java message bundles so Java applications using PHP can usestandard Java localization techniques.</p></s2></s1> <!-- module highlights --><s1 title="ResinModule"><s2 title="jndi_lookup"><p>Retrives an object from JNDI. jndi_lookup is useful in a<a href="soa.xtp">SOA (Service Oriented Architecture)</a>system to locate a Java service.</p><example><?php$conn = jndi_lookup("java:comp/env/jms/jms-connection-factory");$queue = jndi_lookup("java:comp/env/jms/test-queue");...?></example></s2><s2 title="mbean_explode"><p>Explodes a JMX ObjectName into an array.</p><example title="mbean_explode"><?phpvar_dump(mbean_explode("resin:type=WebApp,name=/foo,Host=bar.com"));?></example><results>array(4) { [":domain:"]=> string(5) "resin" ["Host"]=> string(7) "bar.com" ["name"]=> string(4) "/foo" ["type"]=> string(6) "WebApp"}</results></s2><s2 title="mbean_implode"><p>Creates a JMX ObjectName from an array.</p><example title="mbean_implode"><?php$a = array(":domain:"=>"resin", "type" => "ThreadPool");var_dump(mbean_implode($a));?></example><results>resin:type=ThreadPool</results></s2><s2 title="MBeanServer"><p>An object representing a JMX MBeanServer.</p><example><?php$mbeanServer = new MBeanServer();$threadPool = $mbeanServer->lookup("resin:type=ThreadPool");echo "thread-max: " . $threadPool->threadMax;</example><s3 title="lookup"><p>Returns a proxy to the mbean matching the given name.</p><example><?php$mbeanServer = new MBeanServer();$threadPool = $mbeanServer->lookup("resin:type=ThreadPool");</example></s3><s3 title="query"><p>Returns mbean proxies matching the name pattern.</p><example><?php$mbeanServer = new MBeanServer();foreach ($webApp in $mbeanServer->query("resin:type=WebApp,*")) { echo $webApp->name . "<br>\n";}</example></s3></s2><s2 title="resin_debug"><p>Write debugging information to the log. The log is at INFO level.</p><example title="resin_thread_dump"><?php$a = array("a", "b");resin_debug("ARRAY: $a[0]");?></example></s2><s2 title="resin_thread_dump"><p>Produce a thread_dump to the logs. The log is at INFO level.</p><example title="resin_thread_dump"><?php$a = array("a"=>"b");resin_thread_dump();?></example></s2><s2 title="resin_call_stack"><p>Returns an array containing the current PHP function call stack.</p><example title="resin_call_stack"><?phpfunction foo(){ bar();}function bar(){ var_dump(resin_call_stack());}foo();?></example></s2><s2 title="resin_var_dump"><p>Produce a var_dump to the logs. The log is at INFO level.</p><example title="resin_var_dump"><?php$a = array("a"=>"b");resin_var_dump($a);?></example></s2><s2 title="resin_version"><p>Returns the version of Resin running Quercus.</p><example><?phpvar_dump(resin_version());?></example></s2><s2 title="xa_begin"><p>Starts a distributed transaction. All database connections willautomatically participate in the transaction.Returns TRUE for success, FALSE for failure.</p><example><?phpxa_begin();...xa_commit();?></example></s2><s2 title="xa_commit"><p>Commits a distributed transaction. All database connections willautomatically participate in the transaction.Returns TRUE for success, FALSE for failure.</p><example><?phpxa_begin();...xa_commit();?></example></s2><s2 title="xa_rollback"><p>Rolls back a distributed transaction. All database connections willautomatically participate in the transaction.Returns TRUE for success, FALSE for failure.</p><example><?phpxa_begin();...xa_rollback();?></example></s2><s2 title="xa_rollback_only"><p>Marks the current distributed transaction as rollback only. Subsequentattempts to commit the transaction will fail with a warning.Returns TRUE for success, FALSE for failure.</p></s2></s1> <!-- resin module --><s1 name="resources" title="See Also"><ul><li><a href="http://quercus.caucho.com">Quercus home page</a></li><li><a href="http://forum.caucho.com">Caucho Forums, including a Quercus forum</a></li><li><a href="http://bugs.caucho.com">Caucho Bug Tracker</a></li><li><a href="http://maillist.caucho.com/mailman/listinfo">Caucho Mailing Lists</a></li></ul></s1> <!-- see also --> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -