ZMQ, Autobahn, Ratchet -> Sometimes not pushing messages - symfony

I'm facing quite an issue and I really don't know what it's caused by at all. A lot of stuff on my website gets done via websockets, for example pushing messages to clients.
For pushing I'm using ZMQ and Ratchet.
This is the php code:
$UserMessage = array(
'user' => $userid,
'message' => 'Search started',
);
$context = new \ZMQContext();
$socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($UserMessage));
This is the push-server:
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new Some\Bundle\Topic\Pusher();
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onMessage'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8181, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
The problem is: sometimes messages don't get pushed AT ALL. This is happening very randomly. Sometimes it works like a charm for 20 messages in a row, sometimes not.
Does anyone have any idea what this might be caused by? I'm using nginx as a webserver by the way. Are there any kind of logs that might help out?
Regards

Related

Symfony functional test: Current request not set when fetching service from container

One of my services depends on the HTTP_HOST value in the currentRequest object from the requestStack. When this service is used in a functional test it works because I create the client with the host parameter:
$client = static::createClient(array(), array(
'HTTP_HOST' => 'test.' . $this->domain
));
At some point I have the need to get a service from the container that has a dependency on the request so i thought i used the client created with the host value to fetch the service:
$client->getKernel()->getContainer()->get('service')->someMethod();
But the request object is no longer set when the constructer of this service is is called.
Is there any way I can use this service in the test function with a dependency on the Request object ?
Related code:
ControllerTest.php
//Create client with HTTP_HOST
$client = static::createClient(array(), array(
'HTTP_HOST' => 'test.' . $this->domain
));
//Do some request services depending on the request object work because the client is initiated with the HTTP_HOST value
$crawler = $client->request('GET', $redirectUrl);
$this->assertEquals(
1,
$crawler->filter('html:contains("feedback")')->count()
);
//Now I want to check if email feedback is send. This process starts in a EventSubsriber
//I have to trigger this event myself because the $event variable consist of fake data.
$client->getContainer()->get('event_subscriber')->process($event);
//now collect the mail and do some checks
$mailCollector = $client->getProfile()->getCollector('swiftmailer');
$this->assertEquals(1, $mailCollector->getMessageCount());
You should get the Container directly from your created client, as described in the official docs:
$client->getContainer()->get('service')->someMethod();
It may still be necessary to mock the whole service but more code examples would be needed..

name lookup timed out - Cannot find solution

I am working on a local MAMP server, I have a vhost running my site at http://local.mysite.com on a WordPress Install
I am using the JS SDK to log the user in on the front end, and then I am posting to the REST API the access token I am receiving from the JS Login request...
My endpoint has the following:
$data = $request->get_json_params();
$expires = time() + (60 * DAY_IN_SECONDS);
$access_token = new Facebook\Authentication\AccessToken( $data['accessToken'], $expires );
$fb = new Facebook\Facebook([
'app_id' => FACEBOOK_APP_ID,
'app_secret' => FACEBOOK_APP_SECRET,
'default_graph_version' => 'v2.2',
'default_access_token' => $access_token,
]);
wp_send_json($fb->get('/me'));
exit;
But whenever I run this I am getting
PHP Fatal error: Uncaught Facebook\Exceptions\FacebookSDKException: name lookup timed out in /Users/ldewitt/Development/site/wp-content/themes/mysite/includes/Facebook/HttpClients/FacebookCurlHttpClient.php:73
I have searched the site, and everything I am seeing is telling me to up the timeout limit, but doing that just delays when I see the error. I feel like I am very close right now, but obviously something is wrong... can anyone please help me out?
Thanks,
--d
I found the solution... was quite simple...
Because I was working locally and my site was not over HTTPS, the call was failing... I switched this setting in "FacebookCurlHttpClient" and it worked immediately.
CURLOPT_SSL_VERIFYPEER => false,
Thanks to anyone who took some time to look!
--d

Fatal error: Class 'Client' not found in

I got an error while adding Twilio SMS APi to my website. My site is in wordpress and using Woo commerce.
Error : Fatal error: Class 'Client' not found in /var/www/html/++++/wp-content/themes/dokan-theme-v2.2.2-child/functions.php on line 4583
My code is below:
function wl8OrderPlacedTriggerSomething($order_id){
//do something...
//echo get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php';
require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
require( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php');
// Use the REST API Client to make requests to the Twilio REST API
// use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$sid = 'xxxxxxxxxxxxxxxxxxxxxx';
$token = 'xxxxxxxxxxxxxxxx';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
$client->messages->create(
// the number you'd like to send the message to (xxxxxxx)
'xxxxxxxxx',
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => '+xxxxxxx',
// the body of the text message you'd like to send
'body' => "Hey Jenny! Good luck on the bar exam!"
)
);
}
Please help me for the same.
Thank you,
Twilio developer evangelist here.
I think you may need to use the fully qualified namespace for the Client in this case. Try:
$client = new Twilio\Rest\Client($sid, $token);
Let me know if that helps.
Edit
OK, that didn't work. After reading around, I've found that it's not recommended to use require or require_once within a function. I'd recommend you require the autoload file outside of your function, use the namespace and then call the Client inside the function. Like this:
require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
use Twilio\Rest\Client;
function wl8OrderPlacedTriggerSomething($order_id){
$sid = 'xxxxxxxxxxxxxxxxxxxxxx';
$token = 'xxxxxxxxxxxxxxxx';
$client = new Client($sid, $token);
// and so on...
}
make sure that autoload.php and Client.php files are getting loaded properly.
its unable to load client call

Rebus MSMQ appears to be losing messages

I have followed the pub/sub demo with msmq and am loosing messages when the publisher is started before the subscribers. The msmq has already been created.
My Publisher code in one console app
_activator = new BuiltinHandlerActivator();
Configure.With(_activator)
.Transport(t => t.UseMsmq("PaymentsToTake"))
.Subscriptions(s => s.StoreInMemory())
.Start();
/* In the timer code */
MyDateMessage m = new MyDateMessage()
{
NowTime = DateTime.Now,
Counter = _index
};
_activator.Bus.Publish(m).Wait();
_index++;
My Subscriber Code in another console app
_activator = new BuiltinHandlerActivator();
_activator.Register(() => new PrintDateTime());
Configure.With(_activator)
.Transport(t => t.UseMsmq("PaymentsToTake-Receiver1"))
.Routing(r => r.TypeBased().Map<MyDateMessage>("PaymentsToTake"))
.Start();
_activator.Bus.Subscribe<MyDateMessage>().Wait();
Results
When I run the subscriber, I get the message Sending MyDateMessage -> and then when I run the consumer, the first message that comes up is "53 The time is" hence messages 0-52 were lost!
I suspect this is because you are using the in-mem subscription storage, meaning that the publisher does NOT remember who subscribed when it was previously running.
For most (if not all) real-world scenarios, you should choose some kind of persistent storage for subscriptions. It could be a database like SQL Server, or it could even be a local JSON file.
You just need to change the line
.Subscriptions(s => s.StoreInMemory())
into something like e.g.
.Subscriptions(s => s.UseJsonFile(#"subscriptions.json"))
Could you try and see if that fixes your problem? :)

Drupal 7 - Emails are not going out

I'm in need of help for a custom form in which emails are not being sent.
Context: Within Drupal, I have installed the following modules: PHPMailer, SMTP Authentication Support, Mail System and Mime Mail.
Configuring the above modules you have the option to test your configurations and when preforming such tests emails are being sent properly. However, when writing a module for a form, emails are not being sent.
I don't get any type of erros nor message. I just don't get the email.
Here is the snipped of code that I'm using:
function application_form_submit($form, &$form_state) {
$subject = "testing web form";
$body = array();
$body[] = "Mail body";
$send = FALSE;
$mail_message = drupal_mail('application', 'apply-jobs', 'email#gmail.com', language_default(), $params = array(), $from = 'user#test.com', $send);
$mail_message['subject'] = $subject;
$mail_message['body'] = $body;
$mail_system = drupal_mail_system('application', 'apply-jobs');
$mail_message = $mail_system->format($mail_message);
$mail_message['result'] = $mail_system->mail($mail_message);
}
Suggestions?
You've got an odd way of defining optional parameters. This bit:
$from = 'user#test.com'
will evaluate to... nothing
Try changing your drupal_mail() call like this:
$mail_message = drupal_mail('application', 'apply-jobs', 'email#gmail.com', language_default(), array(), 'user#test.com', $send);
I found the solution to my question. The solution is:
The Mail System module allows one to Configure Mail System settings per module, which means that I had to create new mail system for my customized module an indicate the mail system that I want to use. After I did this, all my email are being sent without any problems.
Hope this helps someone, as there is very little information about this.
Thank you all.

Resources