javascript - XMLHttpRequestProgressEvent manipulation from PHP -
i'm struggling issue: have web interface connects, using sockets, various c programs running on routerboards. every time c application sends through socket, php application receives it. works one-shot requests, there 1 case need update interface on browser each time c application sends update, until ends task. can start process using jquery.ajax call php script handles communication c application, , i've managed send xmlhttprequestprogressevent client after each update writing php output buffer , flushing every time script receives through socket has open towards c application. thing is, i'd add meaningful data xmlhttprequestprogressevent, , can see inspecting it has both target , srctarget properties xmlhttprequests. thought responsetext 1 of content of buffer, it's not.
so question is: how can encapsulate data inside xmlhttprequestprogressevent php , , there better way using flush send event?
some code:
c
pipe = popen(command, "r"); while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != null) printf("%s\n", buffer); tcp_send(currenthandler, buffer); } pclose(pipe); (yes, execute process , send output, @ least now).
php
$done = false; while(!$done) { $buffer = socket_read($socket, 128); if (!$buffer || $buffer == "") $done = true; // i'd send value of $buffer well! echo "."; flush(); } javascript
$.ajax({ url: 'myscript.php', type: 'post', datatype: 'json', data: {action: 'runtest', ajax: true}, success: function(data, status, xhr) { console.log('aye!'); }, progress: function(e) { console.log(e); }, error: function(xhr) { console.log('nay!'); console.log(xhr); } }); (of course extended jquery.ajax handle progress event)
update according w3c specification progress event can have lengthcomputable, total , loaded values. fair enough. i'd still able set respective values :)
try node.js maybe can useful you
Comments
Post a Comment