472,959 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 software developers and data experts.

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 2183

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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.