From:             csaba at alum dot mit dot edu
Operating system: Win2K
PHP version:      4.3.4
PHP Bug Type:     Output Control
Bug description:  Multiple clients messing up file reading

Description:
------------
I'm way sorry for posting this here since the culprit is unclear, but you
guys have the best response.  I've written a (non polling) script to
simulate sockets on localhost.  Web page A at http://localhost/test/In.php
is a page that the user enters some text with and it gets written into a
file.



Meanwhile, web page B at http://localhost/test/Out.php is looking at this
file and when it changes, it will update web page B with the new text. 
This is working fine.



Now introduce web page C at the same http://localhost/test/Out.php  In
this case, the second page of B and C to be user refreshed/invoked will
notice the change from page A, and after that it stops refreshing, too.



Something is clearly wrong, but is it PHP 4.3, Apache 2.0.43, IE 5.5, or
(gasp) my code?  I have also coded file_get_contents manually with the
same results.

Reproduce code:
---------------
In the test directory have 3 files:

In.php:

<?php $newWord = @$_POST["newWord"]; ?>

<html>

<head><title>Input page</title></head>

<body>

<form method=post>

<table><tr><td>Enter a word: </td>

<td><input name=newWord value='<?php print($newWord); ?>'></td></tr>

<tr><td>&nbsp;</td><td><input type=submit></td></tr>

</table>

<?php if($_SERVER["REQUEST_METHOD"]=="POST") {

    $fh = fopen("myWord.txt", "w");

    fwrite ($fh, $newWord);

    print("submitted: $newWord");

}

?>

</form></body></html>





Out.php:

<html>

<head><title>Output page</title>

<script type='text/javascript'>

function openSocket() { document.scripts[0].src = "socket.php"; }

</script>

</head>

<body onLoad='openSocket()'>

Your output word is:

<div id=myWord><?php print(file_get_contents("myWord.txt")); ?></div>

</body>

</html>



Socket.php

<?php header("Content-Type: text/javascript; charset=ISO-8859-1");

$txt = file_get_contents("myWord.txt");

for ($ctr=1;$ctr<15;++$ctr) {

    $newTxt = file_get_contents ("myWord.txt");

    if ($newTxt!=$txt) {

        print ("top.document.getElementById('myWord').innerText =
'$newTxt';\r\n");

        print ("document.scripts[0].src = 'socket.php';\r\n");

        die();

    }

    sleep(1);

}

print ("document.scripts[0].src = 'socket.php';\r\n");

Expected result:
----------------
What I expect to have happen is that when multiple browser windows are
aimed at http://localhost/test/Out.php that they will all update right
away when In.php changes the contents of myWord.txt

Actual result:
--------------
Only the latter of the two Out.php windows is updated a single time.

-- 
Edit bug report at http://bugs.php.net/?id=27494&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27494&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27494&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27494&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27494&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27494&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27494&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27494&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27494&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27494&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27494&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27494&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27494&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27494&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27494&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27494&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27494&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27494&r=float

Reply via email to