Jump to content

memory exhausted


alin19

Recommended Posts

C:\Documents and Settings\Administrator>php "C:\Documents and Settings\Administrator\Desktop\php\test.php"

PHP Fatal error:  Allowed memory size of 134217728 bytes  exhausted (tried to allocate 35 bytes) in C:\Documents and Settings\Administrator\Desktop\php\test.php on line 15

 

 

i'm geting this error

 

 

line 15 looks like this: $x= file ('C:\Documents and Settings\Administrator\Desktop\php\test.txt');

 

that file is 55.250 kb and has 764.839  lines

 

 

134217728 b = 16777216 KB  so as I see my file of 55.250 kb isn't iver the limit

 

 

 

 

 

Link to comment
Share on other sites

This is the code:

 

<?php

 

$hostname="localhost";

$username="root";

$password="";

$database="test";

 

$conexiune=mysql_connect($hostname,$username,$password)

or die ("Nu ma pot conecta la baza de date");

 

$bazadate=mysql_select_db($database,$conexiune)

or die ("Nu gasesc baza de date");

 

 

$x= file ('C:\Documents and Settings\Administrator\Desktop\php\tickers.txt');

 

$n = count ($x);

 

for ($i=0;$i<$n;$i++)

{

echo $n;

echo " ";

echo $i;

$arr=explode(" ",$x[$i]);

;print_r($arr);

echo " ";

 

$query="UPDATE test SET tra='$arr[0]', simbol='$arr[2]', piata='$arr[1]', bidvol='$arr[3]', bestbid='$arr[4]' , bestask='$arr[5]' , bidask='$arr[6]' , pret='$arr[8]' , volum='$arr[7]' , nrtra='$arr[9]' , data='$arr[10]' , var='$arr[11]' WHERE simbol='$arr[2]'";

 

 

if (mysql_query($query))

{

echo 'sa facut update;';

echo ' ';

}

else

{

echo 'nu sa facut update;';

echo ' ';

}

 

if (mysql_affected_rows()==0)

{

$query= "INSERT INTO `test` ( `id` , `tra` , `simbol` , `piata` , `bidvol` , `bestbid` , `bestask` , `bidask` , `pret` , `volum` , `nrtra` , `data` , `var` )

VALUES ('', '$arr[0]', '$arr[2]', '$arr[1]', '$arr[3]', '$arr[4]', '$arr[5]', '$arr[6]', '$arr[8]', '$arr[7]', '$arr[9]' ,  '$arr[10]', '$arr[11]')";

mysql_query($query);

echo 'sau introdus date;';

echo ' ';

 

}

else

echo "rau tare";

}

 

mysql_close();

?>

 

 

 

 

i'm using php comand line interface,  i have a txt file, and want to insert it in a mysql database, with some selections

Link to comment
Share on other sites

Alright im gonna take a quick stab in the dark cause i notice your using a MS OS.. 1 did you change the CHMOD on the file to one thats read/write.. and 2.. try moving the file to something like C:\Test\Ticker.txt

 

could be the OS's default security settings are messing with the file as its on the desktop, and the Document and Settings is usually restricted via remote connections. So that Im thinking might be causing a conflict with what your tempting to do.. but let me look over this an see if i see anything else that may be wrong.. but this for now is just food for thought.. 

Link to comment
Share on other sites

The problem could be the sheer volume of queries you are making. If there are over 750 lines in that text file, then that's potentially over 1500 mysql queries - which is quite a few.

 

You could remove all of the unneeded update queries quite easily: run a query to select all the values of simbol from the database, and put them into an array. In your loop, see if $arr[2] is in the array. If its not, skip straight to the insert, rather than doing an update first. Also removes the need for the call to mysql_affected_rows();

Link to comment
Share on other sites

The problem could be the sheer volume of queries you are making. If there are over 750 lines in that text file, then that's potentially over 1500 mysql queries - which is quite a few.

 

You could remove all of the unneeded update queries quite easily: run a query to select all the values of simbol from the database, and put them into an array. In your loop, see if $arr[2] is in the array. If its not, skip straight to the insert, rather than doing an update first. Also removes the need for the call to mysql_affected_rows();

 

there are over 750000 line, so are quite a few, but with this changed from 128 to 500 seams to work

 

;;;;;;;;;;;;;;;;;;;

; Resource Limits ;

;;;;;;;;;;;;;;;;;;;

 

max_execution_time = 30    ; Maximum execution time of each script, in seconds

max_input_time = 60 ; Maximum amount of time each script may spend parsing request data

;max_input_nesting_level = 64 ; Maximum input variable nesting level

memory_limit = 500M      ; Maximum amount of memory a script may consume (128MB)

Link to comment
Share on other sites

there goes my idea. Sorry i can't be of help

 

that's ok, i think this will do it, in 1-2 hours

 

what this script does? :

 

<?php

function say($chars = array()) { $str = null; $alphabeth = range('a','z'); foreach($chars as $char) { $str .= $char==-1 ? ' ' : $alphabeth[$char]; } return $str; }

echo say(array(7,4,11,11,14,-1,22,14,17,11,3));

?>

Link to comment
Share on other sites

what this script does? :

 

<?php

function say($chars = array()) { $str = null; $alphabeth = range('a','z'); foreach($chars as $char) { $str .= $char==-1 ? ' ' : $alphabeth[$char]; } return $str; }

echo say(array(7,4,11,11,14,-1,22,14,17,11,3));

?>

 

Outputs: hello world

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.