473,804 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fast/scalable way of creating a REST webservice api in PHP5?

Howdy!

I am just switching from PHP4 to PHP5. Since there are many different
ways to create XML in PHP5, I'd like to know from the community which
one would be suited best for a REST web service API.

I guess that beeing CPU friendly and using little RAM both count very
high here as criteria.

Here are some methods to be considered (probably not complete):

1) XMLWriter
haven't tested that yet.

2) Using a template framework like PEAR HTML_Template_S igma
I'm doing this for RSS feeds in PHP 4 already. Unfortunately, I have
no comparison with other methods.

3) Writing XML "manually"
like $xml .= '<tag>'.utf8_en code($value).'</tag>';

4) you name it

Thanks to everybody who helps me to investigate/benchmark into the
right direction! I'd also be happy about articles on that topic.

Marian

Mar 19 '07 #1
5 2820
On 19 Mrz., 15:29, "Marian Steinbach" <marian.steinb. ..@gmail.com>
wrote:
>
4) you name it
Of course, I forgot

4) DomDocument

5) SimpleXML
Marian

Mar 19 '07 #2
Marian Steinbach wrote:
3) Writing XML "manually"
like $xml .= '<tag>'.utf8_en code($value).'</tag>';
I tend to do this. Don't forget liberal use of htmlentities(). Unlike
parsing XML, outputting XML manually is very easy, and I find that most XML
output libraries fall into the "overkill" category.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 19 '07 #3
On 19 Mrz., 17:18, Toby A Inkster <usenet200...@t obyinkster.co.u k>
wrote:
Marian Steinbach wrote:
3) Writing XML "manually"
like $xml .= '<tag>'.utf8_en code($value).'</tag>';

I tend to do this. Don't forget liberal use of htmlentities(). Unlike
parsing XML, outputting XML manually is very easy, and I find that most XML
output libraries fall into the "overkill" category.

I just did a very simple comparison of "manual XML writing" and
XMLWriter (which is supposed to be very fast). Surprisingly to me,
XMLWriter is even twice as fast as manual XML writing.

I ran creation of a simple document 10.000 times. Results:

manual.php: ~ 5 seconds
xmlwriter.php: ~ 2 secs

Here is the code I used:

manual.php:

<?php

$start = microtime(true) ;

require './common.inc.php' ;

function makeXmlDocument ($short, $long) {
$ret = '<?xml version="1.0" encoding="UTF-8" ?>
<document>'."\n ";
if (isset($short) && !empty($short)) {
$ret .= '<short>'.htmls pecialchars($sh ort).'</short>'."\n";
}
if (isset($long) && !empty($long)) {
$ret .= '<long>'.htmlsp ecialchars($lon g).'</long>'."\n";
}
$ret .= '</document>';
return $ret;
}

for ($i=0; $i<$num_iterati ons; $i++) {
$xml = makeXmlDocument ($short_string, $long_string);
}

echo 'time used: '.(microtime(tr ue) - $start);
?>

xmlwriter.php:

<?php

$start = microtime(true) ;

require './common.inc.php' ;

function makeXmlDocument ($short, $long) {
$memory = xmlwriter_open_ memory();
xmlwriter_start _document($memo ry,'1.0','UTF-8');
xmlwriter_start _element($memor y, 'document');
if (isset($short) && !empty($short)) {
xmlwriter_write _element($memor y, 'short', $short);
}
if (isset($long) && !empty($long)) {
xmlwriter_write _element($memor y, 'long', $long);
}
xmlwriter_end_e lement($memory) ;
$ret = xmlwriter_outpu t_memory($memor y, true);
return $ret;
}

for ($i=0; $i<$num_iterati ons; $i++) {
$xml = makeXmlDocument ($short_string, $long_string);
}

echo 'time used: '.(microtime(tr ue) - $start);
?>

common.php:

<?php

$num_iterations = 10000;

$short_string = 'Some Short Value';

$long_string = 'Some very long text (truncated here)';

?>

It would be interesting to see which version scales better... That
means: How would the two behave with multiple concurrent requests
(rather typical for a REST API, I guess) and with very large XML
documents (rather untypical for REST services, since lists should be
limited anyway)?

I'll test that.

Marian

Mar 19 '07 #4
On 19 Mrz., 22:47, "Marian Steinbach" <marian.steinb. ..@gmail.com>
wrote:
...
It would be interesting to see which version scales better... That
means: How would the two behave with multiple concurrent requests
(rather typical for a REST API, I guess) and with very large XML
documents (rather untypical for REST services, since lists should be
limited anyway)?

I'll test that.
I just ran a test with JMeter. I altered the scripts a little so that
100 times larger documents would be produced.

Both methods seem to scale equally well, they use the same amount of
RAM (measured with up to 90 concurrent threads).

However, along the comparison result posted earlier, the XMLWriter
version answers almost twice as many requests per time period.

So far,

Marian

Mar 19 '07 #5
Marian Steinbach wrote:
I just did a very simple comparison of "manual XML writing" and
XMLWriter (which is supposed to be very fast). Surprisingly to me,
XMLWriter is even twice as fast as manual XML writing.
It is somewhat surprising. Skimming through the code, as far as I can see,
the only think that might be slowing it down is your use of:

."\n";

to append a line break to strings occasionally. This obviously makes the
generated XML a lot more usable, but it also forces PHP to attempt
interpolation on the string, as it's double-quoted. Does removing these
line breaks speed things up?

If these line breaks *are* what's responsible, I'm going to have to
seriously rethink my own (X|HT|XHT)ML generating code!

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
8410
by: Charles Handy | last post by:
How does FastCGI compare against java Apps running in java app servers like TomCat, Sun One, WebLogic and WebSphere? Is there a business case for switching from CGI to Java? Performance? Productivity? Features? Object orientation? Code Reuse? Any opinions?
2
3021
by: Uwe Mayer | last post by:
Hi, Using PyQt I got a QListView with about 800 entries now (but its intended to be scalable up to about 3000). The first column contains numerical data. Now Qt does the sorting all by its self and quite fast enough. By default it sorts alphanumerically, i.e. 1 10 100 101 110 111 2 ... Solutions on the web suggested left padding the digits with white spaces which didn't work for me.
0
1634
by: SoftComplete Development | last post by:
AlphaTIX is a powerful, fast, scalable and easy to use Full Text Indexing and Retrieval library that will completely satisfy your application's indexing and retrieval needs. AlphaTIX indexing technology provides you with highest indexing performance, possibility to index very large sets of data in minimal time even with memory constraints and unbelievable fast query processing speed. The main AlphaTIX's feature that makes it first and...
0
2529
by: olafmol | last post by:
Hello, i have a problem using a .NET WSDL Webservice from PHP. Using both the NuSOAP lib for PHP4, and the build-in SOAP lib for PHP5 it seems that the SOAP client cannot pass a variable amount of complex datatypes to the WSDL webservice. This is the request-structure we've been using: <EzCreateAuctionArray xmlns=http://www.blabla.com>
1
2236
by: Mike K | last post by:
Howdy, I'm trying to wrap an existing VB 6 COM DLL as a VB.NET 2003 web service. I was able to create web methods for each of the COM DLL's methods I want to expose, but the one method in the COM DLL that subsequently calls a C++ DLL fails. I get an error from the VB6 DLL: ERROR: (453) Can't find DLL entry point PPD in MyDLL32.dll The same method call works fine if I call the COM DLL from a compiled VB6 client application.
1
4395
by: Jeevan | last post by:
Hi , I am working on developing an ASP.NET server control that is based on AJAX and need to call a webservice on a remote domain. To avoid the security warning from IE , I created a proxy webservice in the local application that calls this remote webservice. Every thing works fine as expected. However I need to package the proxy webservice along with the control as a dll so that the users needn't bother about creating a proxy...
0
1105
by: jain.mca | last post by:
Hi Friends.. i m getting a problem how to use REST in webservice which is developed in asp.net, i have created a simple webservice but bydefault it used soap. but my boss wants create it used by REST... plz help me and if any one have a sample code then send me also thanks Manoj
4
1742
by: Marijn | last post by:
Hey everybody, The following has been posted before (2 years ago) but no response was added. Therefor again, the following code for creating xhtml file: <?php error_reporting(6143); $xmlns = "http://www.w3.org/1999/xhtml";
1
9104
by: Thomas Mueller | last post by:
Hi, I'm currently working on C# code consuming a PHP-webservice (soapserver-class of PHP5). A PHP test-client worked fine and achieved the requested data from the service's server. Using the wsdl-file of the webservice, wsdl.exe generated a C#-proxy class errorlessly. I then tried to instantiate the proxy class to access the service: waClient.waService was = new waClient.waService();
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.