I'm currently implementing some logic after getting message from rabbitMQ using basic_get without automatically sending ack for messages being received.
According to the tutorial here (Message acknowledgment section), I can't find the channel reference within the msg itself and send ack like mentioned in above link:
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
That is because in my msg delivery info array there is no such thing channel.
I wonder how could it be that it is missing.
Edit: code snippet of basic get
$msg = $this->channel->basic_get($this->queueName, false);
Here is a var_dump of my message:(Yellow part)
l
According to the AMQP spec get-ok which is the return value of basic-get doesn't include the channel, in contrast to what happens with basic-deliver, which is used when a message arrives for a consumer started with basic-consume.
So the library behaviour is correct.
See https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1022
vs
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L956
When using basic_get (which seems to be discouraged, use basic_consume instead), try acking the message directly from channel using delivery_tag
$this->channel->basic_ack($msg->delivery_info['delivery_tag']);
Related
I've setup a basic webhook php page as modeled on the stripe documentation and listed below. When I send a test event from the Stripe webhooks dashboard, stripe responds "Test webhook sent successfully" with a blankk reponse. However, the output log file is not written to, no email is sent and there is nothing logged to the http server error log or the php error log. My php version is 5.3.3. What am I doing wrong?
<?php
error_reporting(15);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("secret_test_key");
$handle = fopen("webhook.log","a");
// Retrieve the request's body and parse it as JSON
$input = file_get_contents("php://input");
$event_json = json_decode($input);
// Do something with $event_json
if (fwrite($handle, $event_json) === FALSE) {
mail("mike#example.com","Cannot write to webhook.log","");
echo "Cannot write to webhook.log";
exit;
}
mail('mike#example.com','Webhook Event',$event_json);
header(':', true, 200);
//http_response_code(200); // PHP 5.4 or greater
?>
You have a few potential problems. As a quick rule of thumb, the best way to debug this is to start by triggering the event yourself, which you can do simply by loading up your webhook url in a browser yourself. Then you can test it directly and make sure it is doing what you expect it to be doing. There are obviously two possibilities:
Stripe is not triggering your webhook handler for some reason
Your handler is not properly logging itself
The latter first: it could be that Stripe is triggering your handler but it isn't logging that fact successfully. This would mean that both your email logging and file logging are failing. That is actually quite possible. Email logging with the mail function is actually very unreliable, unless you know for a fact that it works. Mail sent with the mail function is dropped silently by most modern email systems (gmail, etc) unless you have your DNS records properly configured, which most people don't. So unless you know for sure that your mail attempt is working properly, it probably isn't. If you also happen to have a permission issue in your attempt to write to a log file (which is not uncommon for a newly setup server), your logs could simply be failing. The easiest way to check that is to load up the webhook URL in a browser yourself. That way you know it is being triggered, and can know for sure if the issue is improper logging or Stripe not calling your webhook.
If you determine for sure that stripe isn't calling your webhook, the most likely culprit would be an invalid HTTPS certificate. Is your webhook connected via HTTPS (it should be)? If so, is it a valid certificate? You can tell your browser to ignore an invalid certificate when you browse your own site, but stripe will simply refuse to send the request if it encounters an invalid certificate.
If none of the above fixes it then it will be time for more digging, but I would start with those: they are probably the most likely problems.
The solution is that $event_json is an object and the fwrite failed because it expects a string not an object. By converting to an array and then serializing I was able to both write to the log and send the email.
$event_json = (array)json_decode($input);
$event = serialize($event_json);
In SOAP UI I am able to pass a few request properties, specifically Username, Password and WSS-Password Type. They are marked in the screenshot below by a red box:
I've tried passing these values in PHP as the second parameter of the SoapClient function like so:
$soap = new SoapClient('https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl',
array("Username" => "blah#example.com",
"Password" => "notarealpassword",
"WSS-Password Type" => "PasswordText"));
But I get the security error: An error occurred when verifying security for the message.
The WSDL I'm calling itself is here, though my question is about passing the request properties this way in general, really: https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl
It is likely that a security header with username and password is sent along with the message itself, but you can not see this header in the normal window in SoapUI.
Click "http log" in the bottom panel of SoapUI to see the whole communication. Look thoroughly for Header ithems.
If any header ithems, they must be set before your function SOAP call in PHP, but after you've constructed the client.
Use __ setSoapHeaders() to set headers in PHP
I was also getting that security error.
I used the soapui tool as well. But i had better success with the Chrome App called Boomerang.
You need to choose WSS PasswordText under Auth and then everything just seems to work.
Then you can even copy the xml that Boomerang generates into PHP and it works as well.
I'm developing a telegram bot using php and a web hook. All it's fine but sometimes I would like to "wait for a reply" from the user. For example:
If the client write /info without any parameters I would like to show a "usage" message and ask&wait for a ID parameter.
I know there is a property "ForceReply" to force for a reply, but when I set it up nothing happens, and I don't know how to know if the client message its a reply for my question.
Do I have to put my php server on hold? (I think it would be a bad practice) Do I have to whait for a type of message?
Thanks
When you use getUpdates or receive updates via a webhook, the update message will contain a field like reply_to_message field. You can use this to compare it to the message you sent.
If you are running your script via webhooks I would assume that it only executes when it receives a message. If so, I would suggest you use something like memcache/redis to store the message you are expecting a reply for and then when the reply comes, you can compare it to the value stored:
<?php
// This script triggers as a webhook
$message = file_get_contents('php://input');
$message = json_decode($message, true);
$cache = new RedisClient('localhost');
if ($message->reply_to_message == $cache->get('original.message.id'))
{
var_dump('message reply received');
}
The example above is some "pseudo" code that you can use in a webhook to check for a reply to a specific message.
I am trying to handle Mandrill's webhook data when I get a bounce I want Mandrill to tell my app which email it was and save various data in a MySql Database.
I am working with PHP here, according to Mandrill they send a URL I give them a $_POST request with JSON data.
Normally I would json_decode() this request, but when I do so, it appears to be blank. To me the JSON looks malformed, but perhaps I need to do something else with it first?
This is what I receive in my script:
[mandrill_events] =>
[{\"event\":\"hard_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"bad_mailbox\",\"bgtools_code\":10,\"diag\":\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces.\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"ts\":1390483382},{\"event\":\"soft_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"soft-bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"mailbox_full\",\"bgtools_code\":22,\"diag\":\"smtp;552 5.2.2 Over Quota\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"ts\":1390483382}]
You have the magic_quotes option set in your server.
You can disable it, or simply remove the trailing slashes from the response and then do the json_decode:
$response = json_decode(stripslashes($_RESPONSE['mandrill_events']), true);
More information about stripslashes: http://php.net/manual/en/function.stripslashes.php
I am using graph api to get a list of albums of a user. Now in case the user signs out or has changes password or any error condition, I do not get any response whereas some error code should be returned. The graph API url when opened in the browser shows the error but on using file_get_contents() i get error 400. On using curl, I get an empty response. Is there any way that I can find out when an error occurs and the reason for it?
The graph API url when opened in the browser shows the error but on using file_get_contents() i get error 400.
Well, that is the HTTP status code that Facebook sends with Oauth errors – nothing wrong about that.
But file_get_contents by default does not show you the actual HTTP response body content in case of an HTTP status codes that signals an error …
… which is just another reason, why one should use the official PHP SDK, which handles all of that nicely and presents you with an exception that tells you exactly what is up.
So do it, please.
(Even with file_get_contents one can get the body content of the response, when setting a “stream context” with the according option first. But using the PHP SDK is way simpler, so again: Please do it.)
I used curl instead of file_get_contents and the issue got resolved.
file_get_contents() gave me error many times when I put https instead of http or If I forgot to put any of them.
Your URL from which you get the content must have "http" at the starting, like:
file_get_contents("http://www.mysite.com");
If this solves it?