Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

open file and print numbers

Posted on 2008-09-29
1
Medium Priority
?
226 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

886 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