473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optimization of mySQL to XML output...

I'm trying to print out a table of mySQL data as XML. However, the
performance I'm getting is REALY bad. Adding the header("Content-Type:
$mime;charset=$ charset"); statement triples the load time of the data
for example. Can someone with more php experience then I look this
over and tell me that I'm stupid and doing it wrong?

define( "DATABASE_SERVE R", "localhost" );
define( "DATABASE_USERN AME", "root" );
define( "DATABASE_PASSW ORD", "" );
define( "DATABASE_NAME" , "mydatabase " );

$method=$_GET['method'];

//connect to the database
$mysql = mysql_connect(D ATABASE_SERVER, DATABASE_USERNA ME,
DATABASE_PASSWO RD);
mysql_select_db ( DATABASE_NAME );
function getDataNames()
{
$Query = "SELECT * from `My Data`";
$Result = mysql_query( $Query );
//$charset = "iso-8859-1";
//$mime = "text/xml";
//header("Content-Type: $mime;charset=$ charset");
print ("<response> ");
while ( $DataName = mysql_fetch_obj ect( $Result ) )
{
//$Return .= "<data><name>". $DataName->DataName."</
name><iocode>". $DataName->IOCode."</iocode><coicop> ".$DataName-
>COICOP."</coicop></data>";
print ("<data>");
print ("<name>".$Data Name->DataName."</name>");
print ("<code1>".$Dat aName->code1."</code1>");
print ("<code2>".$Dat aName->code2."</code2>");
print ("<code3>".$Dat aName->IOComName."</code3>");
print ("<code4>42</code4>");
print ("<code5>".$Dat aName->high_total_IOC omName."</code5>");
print ("<code6>".$Dat aName->high_prod_IOCo mName."</code6>");
print ("<code7>".$Dat aName->high_whole_IOC omName."</code7>");
print ("<code8>".$Dat aName->high_whole_IOC omName."</code8>");
print ("<code9>".$Dat aName->high_whole_IOC omName."</code9>");
print ("</data>");
}
print ("</response>");
mysql_free_resu lt( $Result );
}

Oct 24 '07 #1
6 1579
jf****@vintara. com wrote:
I'm trying to print out a table of mySQL data as XML. However, the
performance I'm getting is REALY bad. Adding the header("Content-Type:
$mime;charset=$ charset"); statement triples the load time of the data
for example. Can someone with more php experience then I look this
over and tell me that I'm stupid and doing it wrong?

define( "DATABASE_SERVE R", "localhost" );
define( "DATABASE_USERN AME", "root" );
define( "DATABASE_PASSW ORD", "" );
define( "DATABASE_NAME" , "mydatabase " );

$method=$_GET['method'];

//connect to the database
$mysql = mysql_connect(D ATABASE_SERVER, DATABASE_USERNA ME,
DATABASE_PASSWO RD);
mysql_select_db ( DATABASE_NAME );
function getDataNames()
{
$Query = "SELECT * from `My Data`";
$Result = mysql_query( $Query );
//$charset = "iso-8859-1";
//$mime = "text/xml";
//header("Content-Type: $mime;charset=$ charset");
print ("<response> ");
while ( $DataName = mysql_fetch_obj ect( $Result ) )
{
//$Return .= "<data><name>". $DataName->DataName."</
name><iocode>". $DataName->IOCode."</iocode><coicop> ".$DataName-
>COICOP."</coicop></data>";
print ("<data>");
print ("<name>".$Data Name->DataName."</name>");
print ("<code1>".$Dat aName->code1."</code1>");
print ("<code2>".$Dat aName->code2."</code2>");
print ("<code3>".$Dat aName->IOComName."</code3>");
print ("<code4>42</code4>");
print ("<code5>".$Dat aName->high_total_IOC omName."</code5>");
print ("<code6>".$Dat aName->high_prod_IOCo mName."</code6>");
print ("<code7>".$Dat aName->high_whole_IOC omName."</code7>");
print ("<code8>".$Dat aName->high_whole_IOC omName."</code8>");
print ("<code9>".$Dat aName->high_whole_IOC omName."</code9>");
print ("</data>");
}
print ("</response>");
mysql_free_resu lt( $Result );
}

Before you can optimize it, you need to find out where the hangup is.
Is it in your PHP code or MySQL?

Try inserting some calls to microtime() at strategic places in your code
and displaying out the results.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 24 '07 #2
On Oct 24, 5:51 pm, jfi...@vintara. com wrote:
I'm trying to print out a table of mySQL data as XML. However, the
performance I'm getting is REALY bad. Adding the header("Content-Type:
$mime;charset=$ charset"); statement triples the load time of the data
for example. Can someone with more php experience then I look this
over and tell me that I'm stupid and doing it wrong?

define( "DATABASE_SERVE R", "localhost" );
define( "DATABASE_USERN AME", "root" );
define( "DATABASE_PASSW ORD", "" );
define( "DATABASE_NAME" , "mydatabase " );

$method=$_GET['method'];

//connect to the database
$mysql = mysql_connect(D ATABASE_SERVER, DATABASE_USERNA ME,
DATABASE_PASSWO RD);
mysql_select_db ( DATABASE_NAME );

function getDataNames()
{
$Query = "SELECT * from `My Data`";
$Result = mysql_query( $Query );
//$charset = "iso-8859-1";
//$mime = "text/xml";
//header("Content-Type: $mime;charset=$ charset");
print ("<response> ");
while ( $DataName = mysql_fetch_obj ect( $Result ) )
{
//$Return .= "<data><name>". $DataName->DataName."</
name><iocode>". $DataName->IOCode."</iocode><coicop> ".$DataName->COICOP."</coicop></data>";

print ("<data>");
print ("<name>".$Data Name->DataName."</name>");
print ("<code1>".$Dat aName->code1."</code1>");
print ("<code2>".$Dat aName->code2."</code2>");
print ("<code3>".$Dat aName->IOComName."</code3>");
print ("<code4>42</code4>");
print ("<code5>".$Dat aName->high_total_IOC omName."</code5>");
print ("<code6>".$Dat aName->high_prod_IOCo mName."</code6>");
print ("<code7>".$Dat aName->high_whole_IOC omName."</code7>");
print ("<code8>".$Dat aName->high_whole_IOC omName."</code8>");
print ("<code9>".$Dat aName->high_whole_IOC omName."</code9>");
print ("</data>");
}
print ("</response>");
mysql_free_resu lt( $Result );

}
tha fact that adding a header triples the load time suggests to me
that what you are annoyed about is the rendering time, rather than the
script time.
(I havent looked at the script to optimise it)
I suggest you goto the command line and simply save the file
grab wget for windows
http://www.google.com/search?hl=en&q...ws&btnG=Search
and on the command line, issue
wget http://example.com/script.php
and see how fast it is (the time will be shown)

Oct 24 '07 #3
tha fact that adding a header triples the load time suggests to me
that what you are annoyed about is the rendering time, rather than the
script time.
Could very well be, I've not tried to time the difference if any when
the application consumes the XML.

Whats more, it turns out that the resulting XML file is over five
megs, which would be the major source of the performance bottle neck.

Other then that, any major issues with my php code? I'm new to the
language (this is my first project with it) and I'm not sure I'm doing
things in the optimal manor.

Oct 24 '07 #4
On Oct 24, 8:21 pm, jfizer <jfi...@vintara .comwrote:
tha fact that adding a header triples the load time suggests to me
that what you are annoyed about is the rendering time, rather than the
script time.

Could very well be, I've not tried to time the difference if any when
the application consumes the XML.

Whats more, it turns out that the resulting XML file is over five
megs, which would be the major source of the performance bottle neck.

Other then that, any major issues with my php code? I'm new to the
language (this is my first project with it) and I'm not sure I'm doing
things in the optimal manor.
well i might use $tempXML .= "<el_1>$var _1</el_1><el_2>$var _2</
el_2>.....";
then print it once.

however have you thought of calling

mysqldump -q -X -u user - p password

using

$command = 'mysqldump -q -X -u user - p password';

passthru($comma nd);

it might be faster! follow jerry's advice and add some calls to
microtime in certain lines and use the difference to see where the
bottlenecks are occuring, since your file is so big i would be tempted
to use on the fly gzipping to get that data down to approximately
1/8th of its size - depending on the data. i know that adds
compression and decompression overhead, but it will speed up the
actual download for a file that size.

also try removing the while loop and using
$num = mysql_num_field s ($query);
to get the number of rows returned, then
use a for loop to concatenate a variable, then print it once you exit
the for loop.
again untested, it might be faster, i seem to remember while loops can
be slow, but i havent actually benchmarked this statement so dont
trust it.

Oct 24 '07 #5
Greetings, jfizer.
In reply to Your message dated Wednesday, October 24, 2007, 23:21:11,

>tha fact that adding a header triples the load time suggests to me
that what you are annoyed about is the rendering time, rather than the
script time.
jCould very well be, I've not tried to time the difference if any when
jthe application consumes the XML.

jWhats more, it turns out that the resulting XML file is over five
jmegs, which would be the major source of the performance bottle neck.

Make sure You have output_bufferin g option enabled and set to value around
Your typical page output size.
It should help speed up page output a bit.
This option disabled by default IIRC.
Check phpinfo(); from Your website for more information.
You may also try to zip output traffic if client application supports that.
Keywords: Output control functions, ob_gzhandler
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Oct 24 '07 #6
AnrDaemon wrote:
Greetings, jfizer.
In reply to Your message dated Wednesday, October 24, 2007, 23:21:11,

>>tha fact that adding a header triples the load time suggests to me
that what you are annoyed about is the rendering time, rather than the
script time.

jCould very well be, I've not tried to time the difference if any when
jthe application consumes the XML.

jWhats more, it turns out that the resulting XML file is over five
jmegs, which would be the major source of the performance bottle neck.

Make sure You have output_bufferin g option enabled and set to value around
Your typical page output size.
It should help speed up page output a bit.
This option disabled by default IIRC.
Check phpinfo(); from Your website for more information.
You may also try to zip output traffic if client application supports that.
Keywords: Output control functions, ob_gzhandler

Output buffering won't do him any good. In fact, it will slow things down.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 25 '07 #7

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

Similar topics

4
2671
by: josef angermeier | last post by:
i wrote a display driver for a lcd segment display which doesnt recognize ascii character so that each character of an output string needs to be converted byte by byte by looking in a const character table. in short, when calling my output function display.output("hallo") i dont want to call the output function at runtime with the ascii character string but with display.output(CONVERTED("hallo")). ok therefor i could maybe write a macro...
1
1396
by: steve | last post by:
I am researching mysql performance optimization. Does anyone who good books, or good url’s for this. I have seen a couple of good books on Amazon, but if you have read anything good, let me know. -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked for conformance to usenet standards Topic URL: http://www.dbforumz.com/mySQL-Good-resources-performance-optimization-ftopict220297.html...
19
2084
by: nospammmer | last post by:
Hello group, I have a rather general but interesting inquiry that is related to PHP and I hope this is the appropriate place to post it. I'm looking for a way to improve dramatically the performance of my PHP application. The application is getting slow as it is taking more load. It is performing a very high number of queries to a database, and I believe that this is taking up most of the ressources.
12
6179
by: WantedToBeDBA | last post by:
Hi all, db2 => create table emp(empno int not null primary key, \ db2 (cont.) => sex char(1) not null constraint s_check check \ db2 (cont.) => (sex in ('m','f')) \ db2 (cont.) => not enforced \ db2 (cont.) => enable query optimization) DB20000I The SQL command completed successfully. db2 => insert into emp values(1,'m')
14
3131
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab compiler for the embedded target. My question is about how compilers optimize certain code sequences. As an example, take the code below. Will the compiler eliminate the actual function call to foo() in the object code generated and just store...
1
2070
by: Karuna | last post by:
Hi, I am new to MySQL. I want to create a script file which will include a number of commands and execute it, just like we do in Oracle. Can any one tell me how to do it? Suppose I want to create a script called "temp" that will contain say 4 create statement. I want someone to show me how to create that file and execute it. And how to capture the output in a separate file like we do in Oracle. And what should be the extension of the...
0
19272
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
3
8816
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a successful 'sudo make install.' Before every attempt I even do a sudo make distclean to make sure I haven't gotten things mucked up from a prior attempt. OS: Mac OS X 10.4.10 MySQL: v5.0.41 for Mac OSX-i686 DBI: v1.58 (installed fine using CPAN)...
18
2086
by: terminator(jam) | last post by:
consider: struct memory_pig{//a really large type: memory_pig(){ std::cout<<"mem pig default\n"; //etc... }; memory_pig(memory_pig const&){
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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
8869
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
8781
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
8551
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
8639
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...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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();...
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.