Apache doesn't run multiple requests
Posted
by
Reinderien
on Server Fault
See other posts from Server Fault
or by Reinderien
Published on 2012-05-30T06:49:37Z
Indexed on
2012/06/02
4:42 UTC
Read the original article
Hit count: 523
apache2
|concurrency
I'm currently running this simple Python CGI script to test rudimentary IPC:
#!/usr/bin/python -u
import cgi, errno, fcntl, os, os.path, sys, time
print("""Content-Type: text/html; charset=utf-8
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>IPC test</title>
</head>
<body>
""")
ftempname = '/tmp/ipc-messages'
master = not os.path.exists(ftempname)
if master:
fmode = 'w'
else:
fmode = 'r'
print('<p>Opening file</p>')
sys.stdout.flush()
ftemp = open(ftempname, fmode)
print('<p>File opened</p>')
if master:
print('<p>Operating as master</p>')
sys.stdout.flush()
for i in range(10):
print('<p>' + str(i) + '</p>')
sys.stdout.flush()
time.sleep(1)
ftemp.close()
os.remove(ftempname)
else:
print('<p>Operating as a slave</p>')
ftemp.close()
print("""
</body>
</html>""")
The 'server-push' portion works; that is, for the first request, I do see piecewise updates. However, while the first request is being serviced, subsequent requests are not started, only to be started after the first request has finished.
Any ideas on why, and how to fix it?
Edit:
I see the same non-concurrent behaviour with vanilla PHP, running this:
<!doctype html>
<html lang="en">
<!-- $Id: $-->
<head>
<meta charset="utf-8" />
<title>IPC test</title>
</head>
<body>
<p>
<?php
function echofl($str)
{
echo $str . "</b>\n";
ob_flush();
flush();
}
define('tempfn', '/tmp/emailsync');
if (file_exists(tempfn))
$perms = 'r+';
else
$perms = 'w';
assert($fsync = fopen(tempfn, $perms));
assert(chmod(tempfn, 0600));
if (!flock($fsync, LOCK_EX | LOCK_NB, $wouldblock))
{
assert($wouldblock);
$master = false;
}
else
$master = true;
if ($master)
{
echofl('Running as master.');
assert(fwrite($fsync, 'content') != false);
assert(sleep(5) == 0);
assert(flock($fsync, LOCK_UN));
}
else
{
echofl('Running as slave.');
echofl(fgets($fsync));
}
assert(fclose($fsync));
echofl('Done.');
?>
</p>
</body>
</html>
© Server Fault or respective owner