Avatar of duncanb7
duncanb7
 asked on

Fatal error on file_put_contents() NOT related memory_limt, execution time, input_time in php

Dear Experts,

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
my csvextract.php
========================================
<?php
ini_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]="\n";
$csv= implode(",",$line);

}
file_put_contents("data.csv",$csv);
?>

Open in new window

PHPLinux

Avatar of undefined
Last Comment
duncanb7

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
a1j

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
duncanb7

ASKER
ulimt -a is for nothing and not the subject of this thread
duncanb7

ASKER
If you keep answer this way, I will ask EE adm to stop your behaviour or account
duncanb7

ASKER
Any suggestion, please conside and read the thread title in detail before you making any comment
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
a1j

Oh  you asking for help and threatening people at the same time? Good luck :-)
duncanb7

ASKER
If you think so, it is not, just hope you conside and read the thread title in detail before you making any fast comment
a1j

This is probably error returned from malloc which means that probably OS denied allocation. Why? Because your ulimit can be set to low numbers.
But I will not follow this thread anymore - you are very rude and need to learn how to work with people.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
duncanb7

ASKER
Hope you can help and be serious to ask and write down what you are asking in detail  at least more words for
other people to be understood
duncanb7

ASKER
I am  sorry to you and  because I got a lot experience  there is a lot of people who just play it aroud not serious.
please stay these thread and I will re-open this thread , your last thread is more kind and more show to others
that you are sincerely to help others because of  more explaination.

I will follow your suggestion no matter that is right and wrong because you are serious to reply this thread
Vimal DM

Hai,

use the below lines on top of ur pages

ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
ini_set("max_execution_time", 0);
ini_set("memory_limit", "10000M");
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
duncanb7

ASKER
The file size of data.csv is just below 1meg byte only
duncanb7

ASKER
It is same as before if change to
 ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
ini_set("max_execution_time", 0);
ini_set("memory_limit", "10000M");
It seems the system not allow $csv is too big in memory from
file_put_contents("data.csv",$csv);
duncanb7

ASKER
Dear Adm,

Please help to reactivate this thread and I get the final answer to this thread
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
duncanb7

ASKER
Dear Ali,

I am  sorry I misundstood your
writing or meaning. Finally
it proved your reply is correct
ulimit -a , and I have checked
the max locked memory is limited
by host company in this thread
as follow
https://www.experts-exchange.com/questions/27052240/Out-of-memory-and-Cannot-allocate-more-memory-for-php-program-in-Linux-at-command-line.html

Anyway, thanks for your reply and
trigger to find  out the final rea
son and answer