MS_MAX_CONCURRENT_REQ - VIES VAT Validation - php

I want to confirm multiple addresses by using https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl.
For some reason, I keep getting the MS_MAX_CONCURRENT_REQ error. I understand the meaning of the error, but I can't understand why it keeps occurring so randomly. I have a sleep of 15 seconds after each call. I could filter out so far that the error occurs mainly with German VAT ID's.
How can I minimize this error without increasing the sleep time?
This is my current SOAPClient Setup.
$client = new SoapClient('https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', ['trace' => false,'keep_alive' => false]);
$result = $client->checkVatApprox([
'countryCode' => $countryCode,
'vatNumber' => $vatNumber,
'traderName' => $traderName,
'traderStreet' => $traderStreet,
'traderPostcode' => $traderPostcode,
'traderCity' => $traderCity,
'requesterCountryCode' => $requesterCountryCode,
'requesterVatNumber' => $requesterVatNumber
]);

As you can find in the documentation of the WSDL of this service:
MS_MAX_CONCURRENT_REQ: Your Request for VAT validation has not been processed; the maximum number of concurrent requests for this Member State has been reached. Please re-submit your request later or contact TAXUD-VIESWEB#ec.europa.eu for further information": Your request cannot be processed due to high traffic towards the Member State you are trying to reach. Please try again later.
There is nothing you can do about it yourself except periodically trying again until it succeeds. Make sure to use a friendly back-off strategy, such as doubling the sleep time between each request in case of failure (also known as "exponential backoff").

Related

When using twilio's php notify API, how do you set your callback URL?

I have the following code and it sends SMS notifications to my phone:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $batch,
'body' => $txt,
'statusCallback' => 'http://postb.in/b/jarblegarble' // <-- this doesn't work
]);
However, even though the sending works, I can't seem to figure out their callbacks.
I'm scouring through their docs and I can't find how to set the callback URL. I see some of their resources use "url" while others use "statusCallback" (heck, one seems to use "redirect"). That being said, I can't seem to post to postb.in using them -- there must be a way to check the status of my notification.
So it turns out I was wrong on two fronts.
1) The callback URL needs to be passed to your messaging service this way:
$notification = $twilio->notify->services($serviceSid)
->notifications->create([
'toBinding' => $bindings,
'body' => $txt,
'sms' => ['status_callback' => 'http://your_callback_url' ]
]);
2) postb.in wasn't working! I was testing the code above, after being assured by twilio support that it was valid, I decided to try and post to my own server and just capture the POSTed content. Sure enough, it was working as they suggested.
Edit: It wasn't clear to me at the time but the callback URL will be called for each SMS sent out for each status update. So that means queued, sent, and delivered. I initially thought that I'd just get a status update for the batch itself as I don't necessarily care for the status of up to 10,000 txt messages.
Your example passes the statusCallback parameter of the individual SMS service API to the universal notify API. This mixing won't work. The individual SMS service sets up a callback for that one particular message, which isn't efficient for batch sends. The universal notify API, in contrast, relies on web hooks, which are globally configured per service.
The simplest thing to do, in your case, is to use the individual SMS service API:
$message = $twilio->messages->create('+15551234567', [ 'body' => 'Hi',
'from' => '+15559876543',
'statusCallback' => 'http://postb.in/b/jarblegarble' ]);
To use the universal notify API, you'll need to set the PostWebhookUrl to the target URL when creating the notification service, and arrange for the code at that URL to handle onMessageSent messages. More at the "web hooks" URL above.
Caveat emptor: haven't tried any of this, and I haven't used Twilio in literally eight years, but the above is my theoretical understanding.

How to properly make a thousand requests to an API in PHP

I have to make a thousand requests to the IGDB API and I am having troubles making this work. Everytime I run my script, it's loading for some time then my web host tells me "Error: there is a problem...It seems that something went wrong." (not very helpful I know).
Since I believe the issue comes from the amount of requests, I have tried reducing it but I am down to 60 requests with a pause of 4 seconds between each and still no success.
My latest try:
$splice = array_splice($array, 0, 60);
foreach($splice as $key => $value){
$request = wp_remote_get('https://igdbcom-internet-game-database-v1.p.mashape.com/games/?fields=*&search='.$value['Name'],
array( 'headers' => array(
'Accept' => 'application/json',
'X-Mashape-Key' => 'Key' )));
$body = wp_remote_retrieve_body($request);
$data_api = json_decode($body, true);
sleep(4);
}
Would anyone know what I am doing wrong? I am running out of ideas...
That's very likely to be nothing more than the timeout response from either PHP or the server.
Although there ways to go around these securities, they aren't for nothing.
You should use CLI to execute cargo queries, not CGI. CGI access is for regular users, whatever their role/priviledges. As a developer, you have access to the code, and to the server (or at least your sysadmin does if you are in a team). You SHOULD use command line to do these queries. It will take less time, will have less chance to fail and you'll have the error logs printed right away unless you redirect them to a file.

Twilio call status always completed even if rejected

I have an application that does the following.
When the client calls a twilio number
my app will be notified, and list of numbers are sent back to be dialed by twilio depending on the agent's availability.
Then depending on the first call's status, if answered => success, otherwise try another agent's number.
First test:
$twiml = new Twiml();
$dial = $twiml->dial();
$dial->number('XXXXXXX'); // Agent A
$dial->number('XXXXXXX'); // Agent B
=> The problem with this version is that all agents are called simultaneously. Don't want that.
Checking call status:
$twiml = new Twiml();
$twiml->dial('XXXXXXXXX',
['action' => 'https://myapp.dev/xml/logger',
'method' => 'POST',
'statusCallbackEvent' =>'answered completed']);
// Log file
..
'CallStatus' => 'completed',
..
=> The call status is always completed even if the agent has rejected the call
Is there a way to implement my application need using twilio Voice SDK without using the complex Taskrouter API ?
Twilio developer evangelist here.
I think you need to check the DialCallStatus parameter which will be the status of the call leg you are making with the <Dial> rather than the status of the original call.
Let me know if that helps at all.

Arbitrary Amazon S3 403 Forbidden in files after changing policy to the folder

I'm working in a template animation system, so I have different folders in S3 with different files inside (html, imgs, etc.)
What I do is:
I change the folder policy like that:
function changeFolderPolicy($folderPath, $client=null, $public) {
if (!$client) {
$client = getClientS3();
}
$effect = 'Allow';
if (!$public) {
$effect = 'Deny';
}
$policy = json_encode(array(
'Statement' => array(
array(
'Sid' => 'AllowPublicRead',
'Action' => array(
's3:GetObject'
),
'Effect' => $effect,
'Resource' => array(
"arn:aws:s3:::".__bucketS3__."/".$folderPath."*"
),
'Principal' => array(
'AWS' => array(
"*"
)
)
)
)
));
$client->putBucketPolicy(array(
'Bucket' => __bucketS3__,
'Policy' => $policy
));
}
After changing the policy, the frontend gets all the necessary files.
However, sometimes, some files aren't loaded because of a forbidden 403. It's not always the same files, sometimes ara all loaded, sometimes none... I don't have a clue since putBucketPolicy is a synchronous call.
Thank you very much.
First, putBucketPolicy is not exactly synchronous. The validatation of the policy is synchronous but the application of the policy requires a nonspecific amount of time to replicate through the infrastructure.
There is no mechanism exposed for determining whether the policy has propagated.
Second, you're bucket policies in a way that fundamentally makes no sense.
Of course, this setup makes the implicit assumption that only one copy of this code would ever run at the same time, which is usually an unsafe assumption, even if it seems true right now.
But worse... toggling a prefix publicly readable so you can copy those files, then (presumably) putting it back when you're done - - instead of using the service correctly, by using the credentials to sign requests to download individual objects you need - - frankly, if I am correctly understanding what you're doing, here, I am at a loss for words to describe just how wrong this solution is.
This seems comparable to a bank manager securing the bank vault with a bicycle lock instead of using the vault's hardened, high-security, built-in access-control mechanisms because a bicycle lock "is easier to open."

Keep messages from ACKing on get() using pecl-amqp

I'm attempting to use pecl-amqp for a project of mine. I'm having difficulties though with the ACK process. I need to manually ACK each message I receive off a queue, but the messages appear to be auto-ACKing when the message is retrieved.
I've set my queue to AMQP_NOACK and am using AMQPQueue->get(AMQP_NOACK) but none of it seems to have any affect, the messages are still removed from the queue without me sending AMQPQueue->ack().
If anyone has any experience with the pecl-amqp I would appreciate the help.
I have been having the same problem but have managed to get the acknowledge mechanism to work using the consume method. Using rabbitmqctl to list the entries in the queue it appears to work OK, though I seems to be getting the messages off the queue in a different order to that in which they were sent - which kind of defeats the object of a queue. My code is as follows:
// Create the queue to be:
// AMQP_DURABLE - messages will withstand a broker restart (i.e. they are written to disk).
// AMQP_NOACK - when consumed messages will not be marked as delivered until an explicit ACK is received.
$q->declare($queueName, AMQP_DURABLE | AMQP_NOACK );
// Bind it on the exchange to routing key.
$q->bind($exchangeName, $routingKey);
// Set the options for our consumption of the messages:
// Get a minimum of 0 msg.
// Get a maximum of 1 msg.
// Don't ACK the message on consumption i.e. explicitly acknoledge later.
$options = array(
'min' => 0,
'max' => 1,
'ack' => false
);
// Get the messages
$results_array = $q->consume($options);
// show the message
print_r($results_array);
$delivery_tag = $results_array[0]['delivery_tag'];
echo 'delivery_tag: [' . $delivery_tag . "].\r\n";
// Acknowledge receipt of the message.
$q->ack($delivery_tag);
For reference, the AMQP extension did not support the AMQP_NOACK correctly. You can get it to do what you want, but it isnt pretty. I am working on fixing that now. FYI, AMQP_NOACK means that you will not have to come back to acknowledge the message later, i.e. as soon as the server sends the message to the client, the server marks the message as ack'ed. There has been some confusion around this, so I wanted to clarify.

Categories