php 5.5 - How to clear memory after file_get_contents executes in php -


i trying add variables couple of files have content.

i using file_get_contents copy contents of particular file , using file_put_contents paste variable values along existing contents file.

the problem that, on first instance works second file pastes has been stored in memory. puts contents first file along contents of second file.

is there way can clear memory before next file_get_contents executes. or concept false here.

here code...

<?php   if ($_post["submit"]) {      $ip = $_post['ip'];     $subnet = $_post['subnet'];     $gateway = $_post['gateway'];     $hostname = $_post['hostname'];     $domain = $_post['domain'];     $netbios = $_post['netbios'];     $password = $_post['password'];       $ipfile = 'one.txt';      $file = fopen($ipfile, "r");     $ipfilecontents = fread($file, filesize($ipfile));      $ipcontent = "ip='$ip'\n";     $ipcontent .= "netmask='$subnet'\n";     $ipcontent .= "gw='$gateway'\n";     $conten = $ipcontent . $ipfilecontents;      $file = fopen($ipfile, "w");     fwrite($file, $ipfilecontents);      fclose($file);      $ipsh = shell_exec('sh path/to/change_ip.sh');        $hostfile = 'two.txt';      $fileh = fopen($hostfile, "r");     $hostfilecontents = fread($fileh, filesize($hostfile));      $hostcontent = "ip='$ip'\n";     $hostcontent .= "m_name='$hostname'\n";     $hostcontent .= "fqdn='$domain'\n";     $conten = $hostcontent . $hostfilecontents;      $fileh = fopen($hostfile, "w");     fwrite($fileh, $hostfilecontents);      fclose($fileh);  $hostsh = shell_exec('sh path/to/modify_hosts.sh');   }         ?> 

i have tried unset, didn't work

$ipfilecontents->__destruct(); unset($ipfilecontents); 

update:

file_get_contents & file_put_contents has concurrency problems. had change method fopen/fwrite/fclose , worked flawlessly. jacinto.

        if ($_post["submit"]) {          $ip = $_post['ip'];         $subnet = $_post['subnet'];         $gateway = $_post['gateway'];         $hostname = $_post['hostname'];         $domain = $_post['domain'];         $netbios = $_post['netbios'];         $password = $_post['password'];           $ipfile = 'one.txt';          $file = fopen($ipfile, "r");         $ipfilecontents = fread($file, filesize($ipfile));          $ipcontent = "ip='$ip'\n";         $ipcontent .= "netmask='$subnet'\n";         $ipcontent .= "gw='$gateway'\n";         $content = $ipcontent . $ipfilecontents;          $file = fopen($ipfile, "w");         fwrite($file, $content);          fclose($file);          $ipsh = shell_exec('sh path/to/change_ip.sh');  //do same next file } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -