Re: File Write Operation Slows to a Crawl....
| From: | fschnittke at execulink dot com | Date: | Mon, 23 Feb 2009 21:07:18 +0000 |
| Subject: | Re: File Write Operation Slows to a Crawl.... | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288713@lists.php.net to get a copy of this message | ||
Hi Shawn:
Yes, good idea, I agree
Thanks....
Fred
> fschnittke@execulink.com wrote:
>> Thanks Paul and Shawn:
>>
>> I can't answer the Why's in your posts, as this is literally my first
>> attempt at PHP, but I will investigate your response and refine my code
>> accordingly.
>>
>> What I did find is that by replacing the following code:
>>
>> $fhandle = fopen("/ramdrive/import_file.txt", "w");
>> foreach($new_format as $data) {
>> fputs($fhandle, "$data");
>> }
>> fclose($fhandle);
>>
>>
>> with this code:
>>
>> $fp = fopen('data.txt', 'a');
>> fwrite($fp, $new_format[$each_rec]);
>> fclose($fp);
>>
>> The parsing finished literally, within seconds. I don't have to worry
>> about anyone else opening this file, so I think this should work ok.
>>
>> Thanks for your help....
>>
>>
>> Fred Schnittke
>>
>>
>> ----------------------------
>> Powered by Execulink Webmail
>> http://www.execulink.com/
>>
> Good job! I posted a minute ago with 2 options, but for your fix I
> would recommend the following:
>
> // move this before your while()
> $fp = fopen('data.txt', 'w'); //notice the 'w' now
>
> // move this after the } that ends your while
> fclose($fp);
>
> Should save even more time because you're not opening and closing the
> file each time through the while().
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
----------------------------
Powered by Execulink Webmail
http://www.execulink.com/