Solved

open file and print numbers

Posted on 2008-09-29
1
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

751 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