Solved

open file and print numbers

Posted on 2008-09-29
1
170 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now