Advertisement
4_2005-2006 Miscellaneous #168985

Simple Explorer

A simple explorer clone. It is heavily commented and shows you a way to show alpha-blended icons, extract icons based on extension or from files themselves, a simple (or recursive) way to collect information about drives and folder, and some other useful stuff for the in-experienced vb.net programmer.

AI

AI சுருக்கம்: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

மூலக் குறியீடு
original-source
Upload
<p>I was given a task to restrict number of downloads , divide the total bandwidth into 2 groups and control the speed of the downloads. So i came up with the idea of doing it with PHP cause mod_bandwidth or mod_throttle werent tailored for the job. Here is the part where i attempt to control the speed of the download.
 <code><font color="#000000">
 <font color="#0000BB"><br>
 <br>
 <br>
&lt;? <br />
$filedownload </font><font color="#007700">= </font><font color="#DD0000">"files/abc.exe"</font><font color="#007700">;
<br />
</font><font color="#0000BB">$time </font><font color="#007700">= </font><font color="#0000BB">10000</font><font color="#007700">;
<br />
</font><font color="#0000BB">$obytes </font><font color="#007700">= </font><font color="#0000BB">150</font><font color="#007700">*</font><font color="#0000BB">1024</font><font color="#007700">; </font><font color="#FF8000">//150k download speed restriction
<br />
</font><font color="#0000BB">$fd </font><font color="#007700">= </font><font color="#0000BB">fopen </font><font color="#007700">(</font><font color="#0000BB">$filedownload</font><font color="#007700">, </font><font color="#DD0000">"rb"</font><font color="#007700">);
<br />
while (!</font><font color="#0000BB">feof </font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">)) {
<br />
&nbsp;&nbsp;&nbsp;&nbsp;list(</font><font color="#0000BB">$usec</font><font color="#007700">, </font><font color="#0000BB">$sec</font><font color="#007700">) = </font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">" "</font><font color="#007700">, </font><font color="#0000BB">microtime</font><font color="#007700">());&nbsp;&nbsp;&nbsp;&nbsp;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$time_start </font><font color="#007700">= </font><font color="#0000BB">$usec </font><font color="#007700">+ </font><font color="#0000BB">$sec</font><font color="#007700">;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$bytes </font><font color="#007700">= </font><font color="#0000BB">ceil</font><font color="#007700">(</font><font color="#0000BB">$obytes</font><font color="#007700">/</font><font color="#0000BB">100</font><font color="#007700">);
<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">, </font><font color="#0000BB">$bytes</font><font color="#007700">);
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">flush</font><font color="#007700">();
<br />
&nbsp;&nbsp;&nbsp;&nbsp;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(</font><font color="#0000BB">$time </font><font color="#007700">&lt; </font><font color="#0000BB">10000</font><font color="#007700">) </font><font color="#0000BB">usleep</font><font color="#007700">(</font><font color="#0000BB">10000</font><font color="#007700">-</font><font color="#0000BB">$time</font><font color="#007700">);
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$i</font><font color="#007700">++;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;list(</font><font color="#0000BB">$usec</font><font color="#007700">, </font><font color="#0000BB">$sec</font><font color="#007700">) = </font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">" "</font><font color="#007700">, </font><font color="#0000BB">microtime</font><font color="#007700">());
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$time_end </font><font color="#007700">= </font><font color="#0000BB">$usec </font><font color="#007700">+ </font><font color="#0000BB">$sec</font><font color="#007700">;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$time </font><font color="#007700">=</font><font color="#0000BB">ceil</font><font color="#007700">((</font><font color="#0000BB">$time_end </font><font color="#007700">- </font><font color="#0000BB">$time_start</font><font color="#007700">)*</font><font color="#0000BB">1000000</font><font color="#007700">)+</font><font color="#0000BB">10</font><font color="#007700">;
<br />
}
<br />
</font><font color="#0000BB">fclose </font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">);
<br />
</font><font color="#0000BB">?&gt;</font>
 </font> </code><br>
 <br>Basically we know how many max bytes we need to send per sec , so we calculate the time in microseconds it took for the code iteration to take place and deduct that time from 1 sec and usleep it for that long , if it took more than 1 sec to complete the iteration ( for example the user is on dialup and cannt receive 150k per sec) than dont put in the delay. <br>
 <br>
 Hope this helps someone. You can find more PHP tips on my site but this one had to be shared in a better way :)
</p>
அசல் கருத்துகள் (3)
வேபேக் மெஷினிலிருந்து (Wayback Machine) மீட்டெடுக்கப்பட்டது