如果你的一段程序需要运行很长时间才能完成,在这段时间内又不想让你的客户等得不耐烦。那么 Progress_bar 可以帮你做到。
Process_bar 利用javascript动态生成一个进度条,并且它会根据你的任务进度来实时改变进度条的进度。例子:- <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
- <html>
- <head>
- <title>Progress Bar Example</title>
- </head>
- <body>
- <?php
- set_time_limit(0);
- include("class.progress_bar.php");
- $pbar = new progress_bar('pbar',1,200,FALSE); //Creates a 200 pixle width progress bar starting at 1 percent with the name pbar auto create = false
- $num_tasks = 20000; // the number of tasks to be completed.
- $pbar->create();
- for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
- {
- echo("<p>Task $cur_task complete.</p>"); // Execute the current task.
- $pbar->set_percent_adv($cur_task,$num_tasks); // tells the progress bar that $cur_task of the 500 tasks is completed.
- }
- ?>
- </body>
- </html>
复制代码 |