Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

open file and print numbers

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

721 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