473,383 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

fread using 99% CPU in Windows with SSL Connection

I'm looking for some information on why fread calls max out CPU usage
on SSL connections in windows. I've tried upgrading PHP (now at 5.1.2)
and OpenSSL (now 9.8) but cannot stop fread() from slamming the
processor on long network requests.

Below is a simple way to reproduce the problem with fgets():

Create two files, one (timer.php) has to be accessable from the web
(HTTP and HTTPS) and the other can be ran from the command prompt
(pingtimer.php). When you run pingtimer.php using SSL, php.exe will
stick at 99% CPU in Task Manager. When you run it using clean sockets,
its idle while waiting for a response.

timer.php :
<?php
sleep(10);
print "<html><body>10 sec. are up!</body></html>";
?>

pingtimer.php:
<?php
//$sock = fsockopen("localhost", 80);
$sock = fsockopen("ssl://localhost", 443);

$query = "GET /timer.php HTTP/1.1\r\n";
$query .= "Host: localhost\r\n";
$query .= "Connection: Close\r\n\r\n";

fwrite($sock, $query);
while (!feof($sock)) {
echo fgets($sock, 128);
}
fclose($sock);
?>

Any info (background, workaround, etc...) would be helpful.

- Joel

Feb 20 '06 #1
2 1981
jo***********@gmail.com wrote:
I'm looking for some information on why fread calls max out CPU usage
on SSL connections in windows. I've tried upgrading PHP (now at 5.1.2)
and OpenSSL (now 9.8) but cannot stop fread() from slamming the
processor on long network requests.

Below is a simple way to reproduce the problem with fgets():

Create two files, one (timer.php) has to be accessable from the web
(HTTP and HTTPS) and the other can be ran from the command prompt
(pingtimer.php). When you run pingtimer.php using SSL, php.exe will
stick at 99% CPU in Task Manager. When you run it using clean sockets,
its idle while waiting for a response.

timer.php :
<?php
sleep(10);
print "<html><body>10 sec. are up!</body></html>";
?>

pingtimer.php:
<?php
//$sock = fsockopen("localhost", 80);
$sock = fsockopen("ssl://localhost", 443);

$query = "GET /timer.php HTTP/1.1\r\n";
$query .= "Host: localhost\r\n";
$query .= "Connection: Close\r\n\r\n";

fwrite($sock, $query);
while (!feof($sock)) {
echo fgets($sock, 128);
}
fclose($sock);
?>

Any info (background, workaround, etc...) would be helpful.

- Joel


whatelse is the CPU supposed to do?

let's see:
do I/O to the network

encrypt the message
open the socket - get data from remote
decrypt the SSL data
move it somewhere (memory/disk)
more processing to display it.

If your CPU is not busy doing other things, it should take as much as it
needs to get the job done.
Feb 20 '06 #2
If you check to source posted above (timer.php), you'll notice that I'm
using a Sleep() call. There should be no data to decrypt until that
call returns. That indicates that the 99% usage is happening while the
socket is being polled for data. True, the SSL layer is more
intensive, but that should not affect the issue at hand as there is no
data being passed over the socket during the 10 sec. sleep call.

- Joel

Feb 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: yexiangmo | last post by:
I am facing a very weird problem of fread in VC6.0. I have a binary file and use following testing code try to read in as bytes It works correctly in Linux and the final statement show the right...
4
by: Meenakshi Matai | last post by:
I am trying to read data from a .dat file using fread. This is how my syntax looks: temp = fread(indata, sizeof(short int), 1, datafile); I looked into the data file in Hex format and saw that...
6
by: Patrice Kadionik | last post by:
Hi all, I want to make a brief comparison between read() and fread() (under a Linux OS). 1. Family read and Co: open, close, read, write, ioctl... 2. Family fread and Co: fopen, fclose,...
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
6
by: Claude Yih | last post by:
Hi, everyone. I noticed an interesting thing about fread() this afternoon. Well, I can't see why so I post this message in the hope of getting some explanation. Please help me. I wrote the...
13
by: 010 010 | last post by:
I found this very odd and maybe someone can explain it to me. I was using fread to scan through a binary file and pull bytes out. In the middle of a while loop, for no reason that i could...
5
by: David Mathog | last post by:
When reading a binary input stream with fread() one can read N bytes in two ways : count=fread(buffer,1,N,fin); /* N bytes at a time */ or count=fread(buffer,N,1,fin); /* 1 buffer at a...
20
by: ericunfuk | last post by:
If fseek() always clears EOF, is there a way for me to fread() from an offset of a file and still be able to detect EOF?i.e. withouting using fseek(). I also need to seek to an offset in the file...
1
by: Marilia | last post by:
Good evening, (I am having a problem that is making me feel stupid. As in, I was expecting some problems (as always), but later on!) I have a binary file which needs to be copied and processed....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.