E
E
Evgeny Fedorov2013-10-01 15:15:03
PHP
Evgeny Fedorov, 2013-10-01 15:15:03

PHP to JS Dataflow?

Please tell me how to get data stream from one php script for getJSON(jQuery).
I need the php script to not wait until it completes its work on the server and send data in json format, but constantly send data in a cycle, but at the same time continue to work. And javascript parsed the stream and packaged it into cells ...
Analog: the php script finished processing one cycle, received data, sent it with a variable (again), which means call me again, I didn’t finish, javascript received data, packages and checks if the variable is equal to 'again' calls json.php again. But this implementation is not entirely correct. I need speed optimization.
Who has any ideas?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2013-10-01
Protko @Fesor

caniuse.com/websockets as a client
php.net/manual/en/book.sockets.php + multithreading (pthread) or multiplexing (socket_select and the other way).
if you are too lazy to write the server, you can simply send the response in pieces and process it manually on the client side .

A
Alexey Zhurbitsky, 2013-10-01
@blo

Comet , specifically the infinite iframe .

M
Max, 2013-10-01
@AloneCoder

Would you like to try something like this ?

N
Nazar Mokrinsky, 2013-10-01
@nazarpc

Here is an example of a server code that spits out content as it comes in:
https://github.com/nazar-pc/CSTester/blob/master/src/nazarpc/CSTester.php#L240

str_repeat(' ', 1024 * 64)

The code above forces the filling and flushing of the buffer, otherwise new portions will not always be returned immediately. You can separate portions with a line break - then individual parts can be detected and parsed.
For client-side read http://stackoverflow.com/questions/7740646/jquery-ajax-read-the-stream-incrementally

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question