473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP: filesize of XML file increases exponentially - HELP

// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS
foreach (array('mime', 'state', 'country') as $val) {
$parser = xml_parser_crea te();
xml_parser_set_ option($parser, XML_OPTION_SKIP _WHITE, 1);
xml_parse_into_ struct($parser, ${$val . 'XML'}, ${$val .
'XMLArray'}, $tags);
xml_parser_free ($parser);
$myXMLArray = ${$val . 'XMLArray'};
for ($i = 1; $i < @sizeof($myXMLA rray) - 1; $i++) {
if ($myXMLArray[$i]['attributes']['ABBREV']) {
$this->{$val . 'Array'}['' .
$myXMLArray[$i]['attributes']['ABBREV']] = $myXMLArray[$i]['value'];
} else {
$this->mimeArray['' . $myXMLArray[$i]['attributes']['ID']] =
$myXMLArray[$i]['attributes']['NAME'];
}
}
}
The following code snipped dynamically reads XML content and parses
into simple 3-dim arrays using xml_parse_into_ struct() command.
However, upon running this snippet I've noticed the data moving
extremely slowly, and then all of a sudden I get a Fatal Error that
states that the allocated memory (I can't reproduce the exact error
again I'm sorry) is full when attempting to allocate 3 bytes. The
error occurred on the xml_parse_into_ struct() line. Following is the
size of the XML files in question:

state.xml - 2521 bytes
country.xml - 12686 bytes

However, upon further inspection I am noticing that I somehow am
increasing the size of /tmp/xml/image_mime.xml exponentially and I
have no idea how I'm doing it!

Current filesize of /tmp/xml/image_mime.xml: 513133515335 bytes!!

Here is the code that will check for the filesize of /etc/mime.types
and if IT changes then change the contents of /tmp/xml/image_mime.xml
to reflect that:
class MIME_TO_XML {

var $sizeTxt;
var $mimeImageRules Array = array('image', 'video');

function MIME_TO_MXL() { // CONSTRUCTOR
return true;
}

//-----------------------------------------* GETTER/SETTER METHODS
*-----------------------------------------
function getMimeXML() { // STRING METHOD CONTAINING XML FILE
CONTENTS
global $basePath;
$fileID = @fopen("$basePa th/xml/image_mime.xml" , 'r');
print_r(filesiz e("$basePath/xml/image_mime.xml" ));
if ($fileID) {
$xmlStuff = fread($fileID,
filesize("$base Path/xml/image_mime.xml" ));
fclose($fileID) ;
}
return $xmlStuff;
}

function getSizeTxt() { // INTEGER METHOD RETURNS SIZE OF
/etc/mime.types STORED IN size.txt OR RETURNS NULL
global $basePath;
$fileID = @fopen("$basePa th/include/size.txt", 'r');
if ($fileID) {
$this->sizeTxt = fread($fileID,
filesize("$base Path/include/size.txt"));
fclose($fileID) ;
if (!is_numeric($t his->sizeTxt)) $this->sizeTxt = '';
}
return $this->sizeTxt;
}
function setMimeXML() { // VOID METHOD TO SET/UPDATE image_mime.xml
WITH XML CONTENT
global $basePath;
$imageVideoMime TypeArray = array();
$fileID = @fopen('/etc/mime.types', 'r') or die('Could not open mime
types file');
$mimeStuff = fread($fileID, filesize('/etc/mime.types'));
fclose($fileID) ;
$mimeArray = explode("\n", $mimeStuff);
for ($i = 0; $i < @sizeof($mimeAr ray); $i++) {
list($mime, $ext) = explode("\t", $mimeArray[$i]);
$objArray = array();
$objArray[0] =& $this; $objArray[1] = 'array_search_b it';
$objArray[2] = $this->mimeImageRules Array;
if ($this->isFoundInMimeI mageRulesArray( $mime))
array_push($ima geVideoMimeType Array, $mime);
}
if (@sizeof($image VideoMimeTypeAr ray) > 0) $xmlString =
$this->getMimeXML() ;
$xmlString = preg_replace('/[\n]+<\/mime_types>$/i', '',
$xmlString);
if (!$xmlString || strlen($xmlStri ng) == 0)
$xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"
?>\n<mime_types >\n";
for ($i = 0; $i < @sizeof($imageV ideoMimeTypeArr ay); $i++) {
$xmlString .= ' <mime id="' . ($i + 1) . '" name="' .
$this->xmlCleanup($im ageVideoMimeTyp eArray[$i]) .
"\"></mime>\n";
}
$xmlString .= '</mime_types>';
if (@sizeof($image VideoMimeTypeAr ray) > 0) {
if (!is_dir("$base Path/xml")) mkdir("$basePat h/xml", 0700);
$fileID = @fopen("$basePa th/xml/image_mime.xml" , 'w') or die("Could
not open $basePath/xml/image_mime.xml ");
fputs($fileID, $xmlString); fflush($fileID) ; fclose($fileID) ;
}

}

function setSizeTxt() { // VOID METHOD SETS size.txt WITH FILESIZE
OF /etc/mime.types
global $basePath;
if (!is_dir("$base Path/include")) mkdir("$basePat h/include", 0700);
$fileID = @fopen("$basePa th/include/size.txt", 'w') or die("Could
not open $basepath/include/size.txt ");
$this->sizeTxt = filesize('/etc/mime.types');
fputs($fileID, $this->sizeTxt); fflush($fileID) ; fclose($fileID) ;
chmod("$basePat h/include/size.txt", 0777); // MAKE IT UNIVERSAL
SINCE IT WILL ONLY CONTAIN AN UNCLEARLY ASSIGNED NUMBER
}
//-----------------------------------------* END OF GETTER/SETTER
METHODS *-----------------------------------------
function isFoundInMimeIm ageRulesArray($ mime) {
list($mime, $stuff) = explode('/', $mime);
if (in_array($mime , $this->mimeImageRules Array)) return true;
return false;
}
function isUnchangedMime File() { // BOOLEAN METHOD
global $basePath;
$sizeTxt = $this->getSizeTxt() ;
if ((is_numeric($s izeTxt) && $sizeTxt !==
filesize('/etc/mime.types')) || !$sizeTxt) return false;
return true;
}

// --* THIS WILL BE THE ONLY METHOD YOU WILL HAVE TO RUN OUTSIDE *--

function process() { // VOID METHOD - RUNS ALL OTHER METHODS
if (!$this->isUnchangedMim eFile()) {
if (!$this->sizeTxt) $this->setSizeTxt() ;
$this->setMimeXML() ;
}
}

// --- END OF PUBLIC FUNCTION process() ----------------------------

function xmlCleanup($tex t) { // STRING METHOD
$text = str_replace('"' , '\\"', $text);
$text = str_replace("'" , "\\'", $text);
$text = str_replace('&' , '&amp;', $text);
$text = str_replace('<' , '&lt;', $text);
$text = str_replace('>' , '&gt;', $text);
$text = str_replace('=' , '&eq;', $text);
return $text;
}

}
Any ideas as to how to approach this problem? Ultimate goal is
probably more simplistic than my approach (no surprise, I can't
approach problems simplistically to save my life: Create an entity
collection of image and/or video MIME types derived from
/etc/mime.types which you should ideally create ONE TIME ONLY.

Phil
Jul 17 '05 #1
0 2265

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

Similar topics

2
2520
by: andi.z | last post by:
wer kann mir mit diesem php - teil helfen .. es scheint nicht zu funktionnieren .. das problem müsste im unteren teil zu suchen sein, nach den tabellen .. <html> <head> <title>andimation.ch</title>
3
11763
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
7
3592
by: theonlydrayk | last post by:
the script that show image is : <?php include('dbinfo.inc.php'); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT file,filesize,filetype FROM user WHERE id=1;"; $result=mysql_query($query); mysql_close();
2
1898
by: underground | last post by:
I need a little help figuring this one out. I have a script that should post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to all the other columns in the row... Could someone help me with this . Below is the complete script...and form.. <?php if(isset($_POST) && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES > 0) { $fileName = $_FILES; $tmpName =...
10
1959
by: underground | last post by:
I need a little help figuring this one out. I have a script that I've modified to post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to all the other columns in the row... Could someone help me with this . Below is the complete script...and form.. <?php if(isset($_POST) && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES && $_FILES > 0) { $fileName = $_FILES;...
5
1852
by: eholz1 | last post by:
Hello PHP, I am having a problem. I know the area of the problem, but not how to solve it. It has to do with a php page with a form on it, and I am trying to perform an insert query into my mysql database. I know that when I "submit" (post) the form, everything goes blank, and the insert query is not run.
3
2199
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it both on the file system and in a mySql database. 90% of the time it works just fine. But for some reason, with some photos, it doesn't work. The image never shows up on the filesystem and there is no entry in the database. I feel it's a problem...
1
6189
by: maconbot | last post by:
hi all, please exuse my email ">" i am working on location. > hey team, thanks for the quick reply. > > i am trying to parse a pop3 account and populate it into flash. > > the how to code... > http://www.derickrethans.nl/parsing_mail_with_php.php > > - is this the class? i am really confused how to plug this into my
3
1889
by: Faisal Shah | last post by:
As the solution.. I have got this script code.. it's an open source so i can modify it.. The problem is it's a guest book script written in very highly and deeply php language that I am not able to understand all.. BUT I am here you guys can read and help me.. From this script i would need your help, You will have to separate 2 things <PLEASE> 1. Bunch of code, Which writes message and gives a unique id to each entry...SO identified...
0
9489
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
9906
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
9885
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
9737
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
8737
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
6562
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();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
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
3
2698
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.