Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-05-17 16:15:13
Point:500 Replies:8 POST_ID:828506USER_ID:11059
Topic:
PHP Scripting Language;Unix Operating Systems;Perl Programming Language
Fatal error on file_put_contents() NOT related memory_limt, execution time, input_time in phpQuestion: I get one php script, csvextract.php, as attached in code area, and I found the error message
"Fatal Error: Out of memory(allocated 3123000)(tried to allocate 71 bytes) in /home/.../csvextract.php line 17"
at the line 17 is exactly at file_put contents() function location.
And I already check my php.ini file and .htaccess file, those are already setting correct memory_limit=128M,
max_execution_time=0, max_input_time=-1, so I believe the error message is NOT related to
memory_limit, max_input_time, max_exexcution_time.
SO what other factors or setting in php.ini will affect the file_put_contents() function ? Is the fatal error
related to magic_quotes_sysbase() and magic_quotes_runtime() ? I got confused about how to use
magic_quotes_sysbase!
When I cut down the file of "data.csv" file size by half or number of row in the file by half,
it is passed and no any error message.So I suspect $csv variable to store the array from file() can NOT
be too much size. Do you think so.? Is there any setting in php.ini related to parsing variable size like $csv as follows
Be reminded my fatal error message is out of memory(allocated 3123000)(tried) and NOT "Allowed memory size 100k exhausted"
If memory_limit is not set correctly, it will report error like " Allowed memory size 100k exhausted" for example only
Please advise
Duncan
"Fatal Error: Out of memory(allocated 3123000)(tried to allocate 71 bytes) in /home/.../csvextract.php line 17"
at the line 17 is exactly at file_put contents() function location.
And I already check my php.ini file and .htaccess file, those are already setting correct memory_limit=128M,
max_execution_time=0, max_input_time=-1, so I believe the error message is NOT related to
memory_limit, max_input_time, max_exexcution_time.
SO what other factors or setting in php.ini will affect the file_put_contents() function ? Is the fatal error
related to magic_quotes_sysbase() and magic_quotes_runtime() ? I got confused about how to use
magic_quotes_sysbase!
When I cut down the file of "data.csv" file size by half or number of row in the file by half,
it is passed and no any error message.So I suspect $csv variable to store the array from file() can NOT
be too much size. Do you think so.? Is there any setting in php.ini related to parsing variable size like $csv as follows
Be reminded my fatal error message is out of memory(allocated 3123000)(tried) and NOT "Allowed memory size 100k exhausted"
If memory_limit is not set correctly, it will report error like " Allowed memory size 100k exhausted" for example only
Please advise
Duncan
<?phpini_set('max_execution_time', 0);ini_set('max_input_time', -1);ini_set('memory_limit', '128M');ini_set('post_max_size', "128M");ini_set('upload_max_filesize', "128M");$csv=file("data.csv");$e=count($csv);$line=array();for ($a=$e-1; $a > 0; --$a) {$line= explode(",",$csv[$a]);$line[4]=$line[4]+100;$line[36]="a";$line[37]="aa";$line[38]="bb";$line[39]="cc";$line[40]="";$csv= implode(",",$line);}file_put_contents("data.csv",$csv);?> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:
Author: duncanb7 replied at 2024-06-28 20:33:41
Thanks for your reply,
the issue is solved finally
Accepted Solution
Author: duncanb7 replied at 2024-05-20 09:31:29
Finally, I make simple php script test running at command line in Linux and runnning it in my IE browser and
found the issue, please help to review the following thread, I need to solve it as soon as possible
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27050790.html
found the issue, please help to review the following thread, I need to solve it as soon as possible
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27050790.html
Assisted Solution
Expert: lexlythius replied at 2024-05-17 17:13:55
166 points EXCELLENT
Author: duncanb7 replied at 2024-05-17 17:08:57
I can't go into the line http://ar.php.net.manual/en/function.forgets.php , Why it is empty?
Author: duncanb7 replied at 2024-05-17 17:07:05
$new_csv[$a] = implode(',', $line);
Try the new variavel of $new_csv
nad file_put_contents("data.csv", $new_csv);
But all is same to get the same error message
Try the new variavel of $new_csv
nad file_put_contents("data.csv", $new_csv);
But all is same to get the same error message
Assisted Solution
Expert: lexlythius replied at 2024-05-17 17:05:37
167 points EXCELLENT
I don't know if the above tip will solve your memory problem, but in any case:
- Avoid loading and writing big data files with shortcuts methods such as file, file_get_contents and file_put_contents, since they take the whole lot of data in and out of memory before each operation. Instead, build and write your data one line at a time, see http://ar.php.net/manual/en/function.fgets.php
- I think setting post_max_size through ini_set is useless, since POST header parsing is already done by the time your PHP script starts
Author: duncanb7 replied at 2024-05-17 17:03:28
I am sorry it is typing mistake it is already $csv{$a].
Assisted Solution
Expert: lexlythius replied at 2024-05-17 17:00:30
167 points EXCELLENT
You have a bug in line 19.
You're destroying the CSV array you're trying to modify by imploding the line back into CSV format.
Try this:
You're destroying the CSV array you're trying to modify by imploding the line back into CSV format.
Try this:
Anyway, it is not advisable to modifiy the same array you're iterating. Better yet:
$new_csv=array();for ($i = 0; $i < $e; $i++) { ... $new_csv[$a] = implode(',', $line);} 1:2:3:4:5: