Program "freezes" while sending large amounts of data...
| From: | Benjamin Smith | Date: | Tue, 28 Sep 2004 05:28:10 +0000 |
| Subject: | Program "freezes" while sending large amounts of data... | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-5115@lists.php.net to get a copy of this message | ||
I've written a PHP-GTK-based Information distribution system, and one of the
things that it has to do is get updates on some 100 MB of data via a "synch".
It works fine, but often it has to transfer files > 3-5 MB in size. Even on a
DSL, this takes a little while. I'd like to update the screen with a "XYZ
bytes transferred" frequently so that the program is responsive and so the
user feels like it's doing something.
Here's the old code:
<?
fputs($conn, $send);
?>
Which is being replaced with something like:
<?
$done=false;
$bytesize=512;
while (!$done)
if ($sv=substr($send, 0, $bytesize)
{
fputs($conn, $sv);
$send=substr($send, $bytesize);
$bytes+=strlen($sv);
// set the widget
$Screen['bytes']->Set_Text(number_format($bytes));
// update the screen.
while (gtk::events_pending())
gtk::main_iteration();
}
else
$done=true;
unset($done);
?>
It works, but for some reason it's very slow with large files. It seems to
"hang" during the loop, and sometimes will transfer data without updating the
screen. Is there a better way to do this? Again, $send can be > 5 MB in size.
Any idea how this could be sped up while keeping the program responsive to
user input?
My guess would be the substr() stuff is the culprit, but there doesn't seem to
be a suitable replacements for fget() when using fputs().
For example, this works very nicely:
<?
while ($line=fgets($conn, 1024))
{
$bytes+=strlen($line);
$Screen['bytes']->Set_Text(Number_Format($bytes));
while(gtk::events_pending())
gtk::main_iteration();
}
?>
but I haven't found a smooth-working equivalent for fputs();
Anyone?
-Ben
--
"I kept looking around for somebody to solve the problem.
Then I realized I am somebody"
-Anonymous