0

This is my code:

    <?php
  $file = fopen('Lista_responsaveis.csv', 'r');
  $i=0;

  while (($line = fgetcsv($file)) !== FALSE)
  {
     $responsavel[$i]=$line[0];
     $i++;
 }
 fclose($file);

 unset($responsavel[0]);

 foreach ($responsavel as $item)
 {
    echo '</br>';
    include("email_gerente_conta.php");
 }

 ?>

And it works very well in my browser : http://174.30.255.100:88/call_email_gerente_conta.php

but if i do this in my cdm:

"C:\Program Files (x86)\iis\PHP\v5.6\php.exe" E:\site\call_email_gerente_conta.php

I get this error message: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in E:\site\call_email_gerente_conta.php on line 8

I already tried increase memory to 128m, 512 and 1g, but still crashing, i'll avoid to use "-d memory_limit=-1", this error message refers to my loop, but i dont understant why this works fine on my browser and not in my cmd, and why a code quite simple and with a csv that has only 3 lines, need this much of memory Any help please

Lessandro
  • 25
  • 7
  • So, basically your question boils down to why it consumes different amounts of memory in different environments, right? I could guess, but first, you need to provide an MCVE! Reason is that without it, your question is off topic and secondly that guessing is bad. – Ulrich Eckhardt Feb 19 '18 at 20:26
  • Hi Ulrich, i just want that my code work on my cmd like works on my browser ( if you could answer the reason about this diference will be a plus for me). Could you tell me whats is a MCVE? and if you can´t help, like Denis, please dont wast your and my time. Thank you – Lessandro Feb 19 '18 at 20:44

1 Answers1

0

You need to change php.ini.

And change number of allowed space.

Link is here

If you have access to specify server (Ubuntu or Windows) You need to change specify file in Apache/conf or php/conf

It can be here or here

Denis Rohlinsky
  • 190
  • 1
  • 2
  • 12
  • Hi Denis, when i use the paramether -d memory_limit=512M or 1024M the falta error message change with it, From Fatal error: Allowed memory size of 134217728 To Fatal error: Allowed memory size of 1073741824 bytes, but just in case i changed in my php.ini with the same result, and i don't use apache, i use iis. – Lessandro Feb 19 '18 at 20:02
  • I recommend you try to allow something like 5000M or more, and see what happened. But you can see same error, i think [here](https://serverfault.com/questions/664034/php-eats-a-lot-of-memory-on-iis). And I recommend for **php** use **Apache**, it doesn't matter on witch os, **Ubuntu** or **Windows**, but for me priority is **Ubuntu**, it personal recommendation. – Denis Rohlinsky Feb 19 '18 at 20:19
  • I already tried with 1GB, and i can't use Apache because that server is from my work. – Lessandro Feb 19 '18 at 20:37
  • 5000M = 1G, rigtht? Just try to use 5G, if it possible. And let me look the answer, i mean error, if it back it. – Denis Rohlinsky Feb 19 '18 at 20:43
  • Hi Denis, i tried a new approach, i change my code for this (sorry put my code here): $row = 1; if (($handle = fopen("Lista_responsaveis.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "Test 1"; $row++; } fclose($handle); } else { echo "Test 2"; } and now my browser show me Test1 and my cmd Test2 ! – Lessandro Feb 19 '18 at 21:09
  • No, but i think the problem was the same, now i put an "If" to not enter in "while" loop if something not right when the script try open the csv. For me the memory error ocur because for some reason the code tried to read the csv and after that enter in a not end loop. So in cmd i have a problem to read my csv (echo Test 2) and in my browser not (echo Test1) – Lessandro Feb 19 '18 at 21:24