Hello. There is a PHP script that I would like to follow during its operation. That is, the function is executed, sends a report, continues to work, and at this time I am watching this report on the html-page.
I decided that I would try to combine PHP with AJAX. It turned out something like this:
ajax.js
function go() { var req = getXmlHttp() var statusElem = document.getElementById('status') req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { statusElem.innerHTML = req.responseText } } req.open('GET', '/script.php', true); req.send(null); statusElem.innerHTML = 'Ожидаю ответа сервера...' } script.php
<?php $somearrays = array('1', '2', '3'); foreach($somearrays as $somearray) { sleep(3); echo $somearray; } ?> Without thinking twice, I pressed the button and waited every 3 seconds for a new “report”. But it was not there. After 3 seconds, no “report” came, but for some reason they all came after 9 seconds, which did not make me very happy.
Question: How to get the results of the function execution in a cycle during its operation?
sleep()(I don’t remember the function, but you will quickly find it). Most likely, it is session blocking. - etki