Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP resets variables
    primarykey
    data
    text
    <p>I'm trying to create a script that creates unique codes and writes them to a textfile. I've managed to generate the codes, and write them to the file.</p> <p>Now my problem is the fact that my loop keeps running, resulting in over 92 000 codes being written to the file, before the server times-out.</p> <p>I've done some logging, and it seems that everything works fine, it's just that after a certain amount of seconds, all my variables are reset and everything starts from scratch. The time interval after which this happens varies from time to time.</p> <p>I've already set <code>ini_set('memory_limit', '200M'); ini_set('max_execution_time',0);</code> at the top of my script. Maybe there's a php time-out setting I'm missing?</p> <p>The script is a function in a controller. I set the ini_set at the beginning of this function. This is the loop I'm going through:</p> <pre><code>public function generateAction() { ini_set('memory_limit', '200M'); ini_set('max_execution_time',0); $codeArray = array(); $numberOfCodes = 78000; $codeLength = 8; $totaalAantal = 0; $file = fopen("codes.txt","a+"); while(count($codeArray)&lt;$numberOfCodes){ $code = self::newCode($codeLength); if(!in_array($code,$codeArray)) { $totaalAantal++; $codeArray[] = $code; fwrite($file,'total: '.$totaalAantal."\r\n"); } } fclose($file); } </code></pre> <p>In the file this would give something like this:</p> <pre><code>total: 1 total: 2 total: ... total: 41999 total: 42000 total: 1 total: 2 total: ... total: 41999 total: 42000 </code></pre> <p>Thanks.</p> <p>Edit: so far we've established that the generateAction() is called 2 or 3 times, before the end of the script, when it should only be called once.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload