alin19 Posted January 18, 2008 Share Posted January 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/ Share on other sites More sharing options...
monkeytooth Posted January 18, 2008 Share Posted January 18, 2008 Whats the rest of the general code? And what are you trying to do more specifically? The more we know the better, we can try to help you Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442695 Share on other sites More sharing options...
alin19 Posted January 18, 2008 Author Share Posted January 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442696 Share on other sites More sharing options...
monkeytooth Posted January 18, 2008 Share Posted January 18, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442707 Share on other sites More sharing options...
alin19 Posted January 18, 2008 Author Share Posted January 18, 2008 all the files are on my computer, and the program it works with a smaller file, Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442714 Share on other sites More sharing options...
monkeytooth Posted January 18, 2008 Share Posted January 18, 2008 Alright, what about your PHP settings.. in the PHP.ini, maybe you need to change the default memory size. Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442732 Share on other sites More sharing options...
monkeytooth Posted January 18, 2008 Share Posted January 18, 2008 memory_limit is what i think you should be looking for if memory serves.. after your done restart your server.. Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442737 Share on other sites More sharing options...
GingerRobot Posted January 18, 2008 Share Posted January 18, 2008 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(); Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442746 Share on other sites More sharing options...
Daniel0 Posted January 18, 2008 Share Posted January 18, 2008 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 There is no such thing as chmod on Windows. Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442747 Share on other sites More sharing options...
alin19 Posted January 18, 2008 Author Share Posted January 18, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442748 Share on other sites More sharing options...
adam291086 Posted January 18, 2008 Share Posted January 18, 2008 is this happening on a remote server? Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442753 Share on other sites More sharing options...
alin19 Posted January 18, 2008 Author Share Posted January 18, 2008 nop, evrything is on my localhost computer Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442755 Share on other sites More sharing options...
adam291086 Posted January 18, 2008 Share Posted January 18, 2008 there goes my idea. Sorry i can't be of help Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442756 Share on other sites More sharing options...
alin19 Posted January 18, 2008 Author Share Posted January 18, 2008 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)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442758 Share on other sites More sharing options...
Daniel0 Posted January 18, 2008 Share Posted January 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86632-memory-exhausted/#findComment-442759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.