Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » SOLVED HttpRequest: is it possible to not wait the server answer?
SOLVED HttpRequest: is it possible to not wait the server answer? [message #60084] Thu, 10 August 2023 13:49 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

let me explain the title.

My U++ client perform 7 queries with an online mysql server through a direct connection. Because the data transfer lasted around 30 seconds I have had this (bad) idea. From my client I have extracted the queries (with data) and transformed them in a PHP file (around 70 kByte included the data to be inserted and updated).
This file was compressed and uploaded to the server via a HttpRequest file upload. On the server side the file is unzipped, echo "OK", and then performs the queries. All works, however my U++ client after done the file trasfer still continue to wait 30 seconds! Evil or Very Mad

It seems that HttpRequest() finish its job only when the php procedure on the server terminated its work... even if the meanwhile the php script echoed some string this is shown only at the very end.

What I would like to do is return control to the user just after the file upload, without to wait the execution of the query. Is there some option in HttpRequest that permit me to do it? Can I gather the echoed string from the server and close the connection? (leaving the server continue its query?

I thought to use a thread. But it seems not to be the solution because after the data transfer the user is not aware of it and may quit the program in any moment.

Thanks in advance for any suggestion.
Luigi

[Updated on: Sat, 12 August 2023 12:12]

Report message to a moderator

Re: HttpRequest: is it possible to not wait the server answer? [message #60088 is a reply to message #60084] Sat, 12 August 2023 11:12 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
I solved the problem. In the meantime I learned that HttpRequest(), it seems, must wait an answer.

The solution is let the script (on the server) send back the wanted answer to the client, then continue the job on the server. The termining answer must be done properly. In PHP this is done in this way ( reference :https:// stackoverflow.com/questions/15273570/continue-processing-php -after-sending-http-response/15273676#15273676 )

ob_start();
// do initial processing here
echo $response; // send the response to the client
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();

//... continue other stuff
//...


These two lines are very important and do the job:
header('Connection: close');
header('Content-Length: '.ob_get_length());
without them the client still hang.

Luigi

[Updated on: Sat, 12 August 2023 11:15]

Report message to a moderator

Previous Topic: HttpRequest - desktop client U++ (accessing java tomcat server)
Next Topic: HttpRequest::GetPath() [FEATURE REQUEST]
Goto Forum:
  


Current Time: Wed May 15 08:43:42 CEST 2024

Total time taken to generate the page: 0.01871 seconds