473,471 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Create 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_create();
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($myXMLArray) - 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 $mimeImageRulesArray = 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("$basePath/xml/image_mime.xml", 'r');
print_r(filesize("$basePath/xml/image_mime.xml"));
if ($fileID) {
$xmlStuff = fread($fileID,
filesize("$basePath/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("$basePath/include/size.txt", 'r');
if ($fileID) {
$this->sizeTxt = fread($fileID,
filesize("$basePath/include/size.txt"));
fclose($fileID);
if (!is_numeric($this->sizeTxt)) $this->sizeTxt = '';
}
return $this->sizeTxt;
}
function setMimeXML() { // VOID METHOD TO SET/UPDATE image_mime.xml
WITH XML CONTENT
global $basePath;
$imageVideoMimeTypeArray = 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($mimeArray); $i++) {
list($mime, $ext) = explode("\t", $mimeArray[$i]);
$objArray = array();
$objArray[0] =& $this; $objArray[1] = 'array_search_bit';
$objArray[2] = $this->mimeImageRulesArray;
if ($this->isFoundInMimeImageRulesArray($mime))
array_push($imageVideoMimeTypeArray, $mime);
}
if (@sizeof($imageVideoMimeTypeArray) > 0) $xmlString =
$this->getMimeXML();
$xmlString = preg_replace('/[\n]+<\/mime_types>$/i', '',
$xmlString);
if (!$xmlString || strlen($xmlString) == 0)
$xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"
?>\n<mime_types>\n";
for ($i = 0; $i < @sizeof($imageVideoMimeTypeArray); $i++) {
$xmlString .= ' <mime id="' . ($i + 1) . '" name="' .
$this->xmlCleanup($imageVideoMimeTypeArray[$i]) .
"\"></mime>\n";
}
$xmlString .= '</mime_types>';
if (@sizeof($imageVideoMimeTypeArray) > 0) {
if (!is_dir("$basePath/xml")) mkdir("$basePath/xml", 0700);
$fileID = @fopen("$basePath/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("$basePath/include")) mkdir("$basePath/include", 0700);
$fileID = @fopen("$basePath/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("$basePath/include/size.txt", 0777); // MAKE IT UNIVERSAL
SINCE IT WILL ONLY CONTAIN AN UNCLEARLY ASSIGNED NUMBER
}
//-----------------------------------------* END OF GETTER/SETTER
METHODS *-----------------------------------------
function isFoundInMimeImageRulesArray($mime) {
list($mime, $stuff) = explode('/', $mime);
if (in_array($mime, $this->mimeImageRulesArray)) return true;
return false;
}
function isUnchangedMimeFile() { // BOOLEAN METHOD
global $basePath;
$sizeTxt = $this->getSizeTxt();
if ((is_numeric($sizeTxt) && $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->isUnchangedMimeFile()) {
if (!$this->sizeTxt) $this->setSizeTxt();
$this->setMimeXML();
}
}

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

function xmlCleanup($text) { // 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 2215

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

Similar topics

2
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> ...
3
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...
7
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 =...
2
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...
10
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...
5
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...
3
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...
1
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......
3
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...
0
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,...
0
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,...
0
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...
0
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,...
1
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...
0
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...
0
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...
0
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 ...
0
muto222
php
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.