Solved

open file and print numbers

Posted on 2008-09-29
1
189 Views
Last Modified: 2008-09-29
hello,
how can I make a code so that it can open a file called (numbers.txt) and print a list of numbers from 1 to 1000000
and when its complete show a message "completed" and show how long it took.
im trying to test some machines and I need this!
0
Comment
Question by:XK8ER
1 Comment
 
LVL 5

Accepted Solution

by:
jericotolentino earned 500 total points
ID: 22594811
Here, try this:
<?php
$filename = 'numbers.txt';
$handle = fopen($filename, 'w+');
 
if (is_writable($filename)) {
	$start = microtime();
	for ($i=1;$i<=1000000;$i++) {
		fwrite($handle,$i."\r\n");
	}
	$end = microtime();
}
else {
	die('File does not have write permissions');
}
 
echo 'Completed. Process took: '.($end-$start).' seconds';
?>

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question