<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Sorry for taking a while to answer -
was on holiday and fully offline :-)<br>
<br>
David Luu wrote:<br>
</div>
<blockquote
cite="mid:CA+V6+ZBcxyaD4gh-U3Yxc_W0wfOGG1cxb9bT+8wtxrM0+8ePog@mail.gmail.com"
type="cite">
<div>Thanks for the response Ken. Sorry, guess I wasn't too clear
about my question, part of my question is also about the
lifecycle of the XML-RPC server. Your response was rather
generic in terms of PHP and not XML-RPC "server" via PHP.<br>
</div>
<div><br>
</div>
<div>With other languages where the HTTP server is bundled/built
into the XML-RPC server, the lifecycle is you start up server,
that's the instance of the server and it ends when you shut down
the server. During its lifecycle/operation, all requests to the
server go through the same XML-RPC server instance.</div>
<div><br>
</div>
<div>From your response and a re-looking at the code, I'm using
these as reference</div>
<div><br>
</div>
<div><a moz-do-not-send="true"
href="http://phpxmlrpc.sourceforge.net/server.php?showSource=TRUE">http://phpxmlrpc.sourceforge.net/server.php?showSource=TRUE</a></div>
<div>PHP XML-RPC server doc: <a moz-do-not-send="true"
href="http://phpxmlrpc.sourceforge.net/doc-2/ch07s05.html">http://phpxmlrpc.sourceforge.net/doc-2/ch07s05.html</a></div>
<div><br>
</div>
<div>It appears the lifecycle is the "XML-RPC server" is
initialized on an HTTP request to any PHP page that invokes the
"XML-RPC server" (whether directly in the page code or via code
in include file), and that the server sorta stops after it
completes the HTTP response back to the requesting client?
Because otherwise, the PHP module on the HTTP server would keep
spawning XML-RPC server instances if its lifecycle didn't end
with the response being sent back (memory leak, etc.), unless of
course the PHP module knew to reuse the server on subsequent
requests.</div>
</blockquote>
<br>
You are correct. The lifecycle of the xmlrpc server is (by default)
as long as 1 http request.<br>
It's not a "server" in the way one normally envision it, ie. a
long-running process.<br>
It does not have "start" and "stop" methods either.<br>
It just does its job when asked to, leaving lifecycle management to
the php+webserver engine. Start webserver => xmlrpc ready to be
used, stop the webserver => no more xmlrpc endpoint available.<br>
Otoh a single xphpxmlrpc server object could serve many xmlrpc
requests if the php code which uses it was developed in such a way -
it's just not the default way of using it.<br>
<br>
Long story:<br>
<br>
This is the standard execution model of php: all objects are
instantiated on every "page" request, and die with it (there are a
few exceptions such as persistent db connections, but those are
normally handled by C code from php extensions).<br>
They are also not shared between different http requests (so 10
concurrent requests will each get its own xmlrpc server object).<br>
This seems wasteful from a processing standpoint (both cpu and ram),
and it actually is - but it comes with a major advantage: developers
never have to worry about memory allocation and proper freeing of
resources - as all memory allocated by the script and other used
resources are automatically deallocated / torn-down by the language
engine itself.<br>
And real-life has shown that in 90% of real-life usage, the time
spent in creating / destroying php objects is extremely small
compared to the time spent doing the actual computation (eg.
querying a database and waiting for results).<br>
<br>
Side note: a big performance booster for php is a so called "opcode
cache", such as apc, xcache or eaccelerator. Those will hook into
the php engine and avoid the compilation of the php script itself
(into internal engine opcodes), which by default happens on every
single http invocation as well (brrr, scary! but it makes developers
lives easier by avoiding them to hit the "compile" button). If you
have many lines of php code executing, this can give you a speedup
of a factor of 10.<br>
<br>
There are of course other execution / programming models available:<br>
<br>
a) a php script might serialize objects and store them in between
http requests, eg. in a memcache pool. This is of course only useful
when object instantiation takes longer than access to memcache +
object deserialization. It also introduces opportunities for locks,
races, and all kind of hard-to-debug stuff<br>
<br>
b) instead of using the "standard php on a webserver" installation,
run a standalone php script which listens to http requests on its
own. This way php objects can stay in memory for ever, and behave
like they would in a JVM. You will get faster execution times
(possibly, it's not 100% sure as all http parsing will now be
probably handled by php code instead of C code), and a bigger risk
of memory leaks. Look for a project called "nano" for a
webserver-written-in-php. Or use php 5.4 which has a built-in
webserver (but so far all php core devs recommend using it only for
testing, not for prod). There are probably other projects available
in this space as well (maybe the hiphop stuff from facebook or other
"alternative php engines")<br>
<br>
I would have to dig into the phpxmlrpc test suite to find out if it
is factually correct, but iirc in the past I tested the phpxmlrpc
server object to make sure it could work in the "single,
long-running script" scenario, and there where no memory leaks of
its own. <br>
<br>
Hope it helps<br>
Gaetano<br>
<br>
<blockquote
cite="mid:CA+V6+ZBcxyaD4gh-U3Yxc_W0wfOGG1cxb9bT+8wtxrM0+8ePog@mail.gmail.com"
type="cite">
<div><br>
</div>
<div>David</div>
<br>
<div class="gmail_quote">On Tue, Dec 25, 2012 at 3:35 AM, Ken
Almond <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:ken@almondenterprises.com" target="_blank">ken@almondenterprises.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Apache
(when configured) loads a php.so module – so PHP is
‘loaded’ (ready to go) as part of apache startup.</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Yes,
when HTTP hits Apache, the server.php file is loaded
(on each HTTP request). Since php.so module is
already running as part of apache startup – its ‘very
fast’ BUT you do want to keep server.php files smaller
(1,000(s) of lines) instead of 50,000(s) of lines.
We used a URL name space to have multiple server.php
files – e.g. <a moz-do-not-send="true"
href="http://host/login.php" target="_blank">http://host/login.php</a>
(login.php is a server.php file), <a
moz-do-not-send="true"
href="http://host/accounts.php" target="_blank">http://host/accounts.php</a>,
etc. - e.g. 1 ‘server.php’ for grouping of web
services. The login.php and account.php, and x.php
and y.php can call into shared library.php(s) but
again, overall, keep the #includes smaller so each
server.php is not ‘too large’. We achieved average
10ms (where php called MSSQL inside) response time for
1,000(s) of simultaneous users on single apache
server.</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Bonus
tip</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">We
put 1<sup>st</sup> apache server in DNZ zone
(publically available for URL) and then used apache
reverse proxy over to internal apache that that
actually called the server.php(s) for very strong
protection. Worked very well. Then as we grew,
we used the reverse proxy to load balance – but apache
also has other forms of load balance.</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Good
Luck</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Ken</span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
<a moz-do-not-send="true"
href="mailto:phpxmlrpc-bounces@lists.usefulinc.com"
target="_blank">phpxmlrpc-bounces@lists.usefulinc.com</a>
[mailto:<a moz-do-not-send="true"
href="mailto:phpxmlrpc-bounces@lists.usefulinc.com"
target="_blank">phpxmlrpc-bounces@lists.usefulinc.com</a>]
<b>On Behalf Of </b>David Luu<br>
<b>Sent:</b> Monday, December 24, 2012 10:35 PM<br>
<b>To:</b> <a moz-do-not-send="true"
href="mailto:phpxmlrpc@lists.usefulinc.com"
target="_blank">phpxmlrpc@lists.usefulinc.com</a><br>
<b>Subject:</b> [phpxmlrpc] How to start/stop XML-RPC
server?</span></p>
<div>
<div class="h5">
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal">I'm just looking into XML-RPC
server with PHP, so have not much idea about its
implementation and design.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">With other language
implementations, it's easy to understand, as you
can start/stop the server from command line (or
other interface like UI, XML-RPC call for stop,
etc.) as all the server functionality can be
combined with the XML-RPC server itself as a
single self contained binary/application.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">With PHP, the PHP code is
served by a web/application server. So wanted some
clarification:</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">
* how do you start the server? Start up the
web/application server (Apache, IIS, etc.), then
hit the URL to the PHP script that creates the
server instance? Are the XML-RPC requests
(different XML-RPC method calls) going to same URL
or different one?</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">* how do you stop the PHP
XML-RPC server? Stop the web/application server
itself? (e.g. Apache, IIS, etc.) Or is there a way
to stop it w/o turning off the whole
web/application server or say killing PHP.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">David</p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
phpxmlrpc mailing list
<a class="moz-txt-link-abbreviated" href="mailto:phpxmlrpc@lists.usefulinc.com">phpxmlrpc@lists.usefulinc.com</a>
<a class="moz-txt-link-freetext" href="http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc">http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc</a>
</pre>
</blockquote>
<br>
</body>
</html>