Viewed   78 times

I come from more of a Java background. In the last year or two, it's become somewhat popular to do server push over HTTP using long-lived HTTP connections in Comet. It's an extremely useful technique.

So I'm curious what the equivalent is with Apache + PHP + Javascript? One option I see is just using straight AJAX calls (eg with jQuery) but I don't really know how Apache handles them or how I can implement such a thing on the serverside with PHP. Any ideas? Any good resources on this kind of thing?

 Answers

4

You can use Comet programming techniques in PHP. I think a good place to start is this post, describing how to implement Comet in PHP.

Monday, August 29, 2022
 
5
data: { activitiesArray: activities },

That's it! Now you can access it in PHP:

<?php $myArray = $_REQUEST['activitiesArray']; ?>
Wednesday, October 19, 2022
2

you problem that selector ('#services') takes only first input value. You should remove id and just serialize form as below.

If all you need to pass is all values from form you can use

data: $('form#my-form').serialize() // this code puts all of the inputs into passable and readable for PHP, way.

And then in $_POST['service'] will be an array of inputs values.

For example:

<form action="save.php" method="post" id="services">
    <input type="text" name="service[0]" value="1st Service" />
    <input type="text" name="service[1]" value="2nd Service" />
    <input type="text" name="service[2]" value="3rd Service" />
    <input type="text" name="service[..]" value=".. Service" />
    <input type="text" name="service[N]" value="N Service" />
</form>

In your JS:

$.post($('form#services').attr('action'), $('form#services').serialize(), function(response) {});

And then in save.php you can get an array in $_POST:

var_dump($_POST['service']);

Hope that's is exactly what you need.

Monday, October 31, 2022
 
r2d2
 
3

TL;DR: You must call both grpc::Server::Shutdown() and grpc::CompletionQueue::Shutdown() (for each completion queue used in the service) to shut down cleanly.

  1. If you call cq_->Shutdown(), the only observable effect is that subsequent calls to Service::AsyncService::RequestFoo() (the generated method for the corresponding Foo RPC) fail with an assertion. From reading the documentation of the corresponding C API method (grpc_completion_queue_shutdown()), it appears that it is illegal to add new work to the queue—i.e. by calling RequestFoo()—so I added an is_shutdown_ member to my service wrapper classes (protected by a mutex) so that no enqueue attempts are made after cq_->Shutdown() is called. However, after doing this, the completion queue blocks indefinitely in cq_->Next(). None of the enqueued tags complete (with an error or otherwise).

  2. If instead you call server_->Shutdown(), all of the enqueued tags complete immediately (with ok == false). However, the completion queue continues to block indefinitely in cq_->Next().

Calling both cq_->Shutdown() (for each defined completion queue) and server_->Shutdown() results in a clean shutdown.

One caveat: if you use grpc::ServerContext::AsyncNotifyWhenDone() to register a tag for call cancellation, these will not be returned by cq_->Next() if the server shuts down before the initial request is received for that call. You will need to be cautious with the memory management of the corresponding tag structure, if you want to avoid memory leaks.

Monday, November 21, 2022
 
2

I haven’t tried to run your code but have noticed that Chrome does not allow HTTP/2 push with an untrusted HTTPS certificate (e.g. a self-signed one not yet added to the trust store). Raised a bug with the Chrome team.

If you have the red unsecure padlock item then you could be hitting this issue too. Add the certificate into your trust store, restart Chrome and reload the site where you should get a green padlock.

Note Chrome needs a certificate with a Subject Alternative Name (SAN) field matching the domain so if you’ve just got the older Subject field then it won’t go green even after adding it to your trust store.

Another option is to look at the Chrome HTTP2 frames by typing this into your URL:

chrome://net- internals/#http2

If you see the push promise frames (with a promised_stream_id), followed by the headers and data on that promised_stream_id then you know the sever side is working.

Wednesday, October 26, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :