the question may be stupid but its really important for me to understand how i can do it in the right way.
Let's say that we have the following script
<?php
//set count_bytes
$count_bytes = true;
//set count_bytes
$bytes = 0;
$url = "http://127.0.0.1:" . 8000;
$file_handler = @fopen( $url, "rb" ) or die( "Not Working" );
foreach ( $http_response_header as $h )
{
header( $h );
}
while ( ! feof( $file_handler ) )
{
$response = stream_get_line( $file_handler, 4096 );
if($count_bytes === true)
{
$bytes += strlen( $response );
}
echo $response;
}
fclose($file_handler);
?>
As you can see i am using the variable $count_bytes which is bool. In the while loop you can see that the if statement is being checked everytime. Is there any way to optimize this so the check will only be done for one time?
I guess the one solution is to make the while loop 2 times and call the one we want depending on the bool value of $count_bytes but that is too much code and of course if we have huge code this is bad.
Thanks hope you understand me