0

I try to use xbuf_frurl to start a worker to do some post-processing.
The worker will finish the job without returning anything.
Thus, the original script can respond to client faster.

So, I try to set the timeout=0ms in xbuf_frurl, hoping that it can return immediately and do the rest of the code and return 200.

xbuf_frurl(&buf, "localhost", 80, HTTP_GET, "/postprocessing", 0, 0);
xbuf_ncat (reply, buf.ptr, buf.len);

But, it seems not to timeout immediately, since the buffer is not null.

Is there any better way to do so?

Gil
  • 3,279
  • 1
  • 15
  • 25
k.k. lou
  • 1,805
  • 2
  • 13
  • 16
  • For internal usage, xbuf_frurl need not the complicated http headers. I think it is good to have a parameter to switch off the standard headers, and send the user's headers only. – k.k. lou Dec 15 '12 at 14:58
  • That would break the HTTP protocol that xbuf_frurl() is supposed to use. To just 'ping' the server you should rather start a connect() / send() shutdown() close() cycle which will run much faster. – Gil Dec 20 '12 at 10:35

1 Answers1

0

The xbuf_frurl() timeout is aimed at failing faster when the target host is not accepting the TCP connection.

So, to answer your question, the timeout will have no influence on the reply time since the server is always online.

I am not sure that querying a servlet from another servlet (or self) is the best way to do what you want to do, but I can't give you a better strategy if I don't know what your goal is (the mysterious 'posprocessing' can surely be triggered more efficiently than by using an HTTP connection).

If you want to use an HTTP connection, you can have the servlet to send a minimal answer by using an incorrect HTTP status code is the 1-99 range: this is used to prevent G-WAN from adding missing HTTP headers, for example to send naked JSON payloads.

Gil
  • 3,279
  • 1
  • 15
  • 25