I am trying to connect Splunk using PHP SDK but I am getting following errors:
https://api.9xnn-6gtz.data.splunkstorm.com:80/services/auth/login Warning: array_shift() expects parameter 1 to be array, null given in /home/u354848659/public_html/oauth/splunk/Splunk/Http.php on line 124
Warning: Invalid argument supplied for foreach() in /home/u354848659/public_html/oauth/splunk/Splunk/Http.php on line 126
Login Failed. Reason: String could not be parsed as XML
$SplunkExamples_connectArguments = array(
'host' => 'example.com',
'port' => '80',
'username' => 'xxxx',
'password' => 'xxxx',
'token' => 'xxxxxxxxxxx',
);
I passed all above details. But when I am trying to run it is not working. Kindly help me out in resolving the issue at the earliest. Thanks
You need to give more code of what you're doing with this. One of your warning messages states you're passing a null, Here you're showing us an array, which gives me some ideas of what might be wrong, but you're not showing us how you use this array. You should try putting together a SSCCE.
From the getting started guide, the example does not pass a token. The reason for this, if you dig into the documentation you'll see that if you provide a token, then the username and password is ignored and you don't need to call login().
Furthermore, using the PHP SDK (and other SDKs), you need to hit the Splunk REST API port, which by default is port 8089, not port 80. This is configurable of course, so you should double check with your Splunk Administrator.
Related
While sending a newsletter-kind-of mail I came across this weird problem.
In a for loop, I loop through all the users in a database and try to send them all an HTML mail with some basic information. Now the thing is that the first 200 or so mails run fine, but then the script crashes and gives the following error:
Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:140D00CF:SSL routines:SSL_write:protocol is shutdown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 263 Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:140D00CF:SSL routines:SSL_write:protocol is shutdown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 263 Fatal error: Uncaught exception 'Zend\Mail\Protocol\Exception\RuntimeException' with message 'Could not read from smtp.gmail.com' in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php:308 Stack trace: #0 /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php(339): Zend\Mail\Protocol\AbstractProtocol->_receive(300) #1 /opt/zendframework2/library/Zend/Mail/Protocol/Smtp.php(358): Zend\Mail\Protocol\AbstractProtocol->_expect(221, 300) #2 /opt/zendframework2/library/Zend/Mail/Protocol/Smtp.php(394): Zend\Mail\Protocol\Smtp->quit() #3 /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php(115): Zend\Mail\Protocol\Smtp->_disconnect() #4 [internal function]: Zend\Mail\Protocol\AbstractProtocol->__destruct() #5 {main} thrown in /opt/zendframework2/library/Zend/Mail/Protocol/AbstractProtocol.php on line 308
Now, I'm not to familiar with smtp, ssl & tls but I believe the most important line of the error is: 'Could not read from smtp.gmail.com'. Which doesn't make any sense to me.
We send emails all the time ( lost passwords, registration mails, etc ) and this always (to my knowledge) works fine. The script just crashes after it has sent too many mails in a short period of time.
Ok, that was the problem, now let me explain the setup :)
I'm running Zend 2.2.6 on a standard LAMP server ( PHP 5.3.10 ) and using standard SMTP mail scripts provided by Zend. We're using Google business apps as a mail client. The following is the first couple of lines of the mail script:
<?PHP
namespace Mail\Mails;
use Zend\Mail;
use Zend\Mail\Message;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
use Mail\Config\Config;
class Base
{
private $transport, $text, $html, $to, $subject;
public function __construct()
{
$config = new Config();
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'mydomain.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'username' => $config->username,
'password' => $config->password,
'ssl' => 'tls'
),
));
$transport->setOptions($options);
$this->transport = $transport;
// This happens in different parts of the code.
$this->subject( $subject );
$this->to( $address );
$this->html( $html );
$this->text( $text );
$this->send();
}
?>
What I've tried so far:
Running the script again
This has different outcomes: sometimes it breaks earlier, sometimes it breaks further on, but this proves the script doesn't break on a particular address. I get the feeling that the server has some kind of cooling down: the first run it processes like 200 addresses but when I rerun the script directly after, it can break after 20 addresses. When I try it like an hour later the script breaks after about 200 addresses again.
I've tried to change the ssl option to 'ssl' and the port option to '465' but this has the exact same result.
Is anybody familiar with this problem? I'm not really sure where to look for problems, maybe someone can give me a push in the right direction?
Thanks in advance!
Older site but probably your problem
http://www.serversmtp.com/en/limits-of-gmail-smtp-server
That's because Google places all sorts of limits on the use of its SMTP service by marketers. Those limits begin with a restriction on the number of recipients who can receive the same message. If Gmail's SMTP server detects that your message is going to more than 500 people, it disables your account.
I am working on an api for a client. I have received the following information:
API Url: http://xyz-crm.example/WebAPI/Custom/project_name/XML/
Username: foobar
password: spameggs
I need to configure the PHP SOAP client for the same in non-WSDL mode. I have written the following but it does not seem to work:
$wsdl = null;
$options = array(
'uri' => 'http://xyz-crm.example/WebAPI/Custom/project_name/XML/',
'location' => 'http://xyz-crm.exmaple.com/WebAPI/Custom/project_name/XML/',
'login' => 'foobar',
'password' => 'spameggs'
);
$client = new SoapCLient($wsdl, $options);
I just want to make a successful ping to the api at first. See if things are working fine. What am I doing wrong here?
Update 1
I made the following changes:
$wsdl = null;
$options = array(
'uri' => "http://xyz-crm.example/WebAPI/Custom/project_name/XML/",
'location' => "http://xyz-crm.example/",
'Username' => "foobar",
'Password' => "spameggs",
'soap_version' => '1.2'
);
$client = new SoapClient($wsdl, $options);
$client = $client->getListings();
I get the error: looks like we got no XML document
[Edit by me, hakre: This update was done as feedback to answer #1. It changes the location option using a shortened URL (reason not given by OP) and it adds the soap_version option (as suggested in answer #1, but not as constant but as string (containing an invalid value), so there should be no wonder this creates an error, a correct option value is given in answer #1 (the SOAP_1_1 constant) and by intention, the correct value would be the SOAP_1_2 constant for this example). Error message as commented by OP was "SOAP Fault: Wrong version."]
Update 2
I tried the following but it still fails:
$listing = $client->getListings();
$request = $client->__getLastRequest();
The execution stops at the first line itself without ever going to the second one.
[Edit by me, hakre: As review has shown wrong configuration options in Update 1 already which are not addressed in Update 2 it would be a miracle if it still wouldn't fail. The execution stops because an Exception is thrown and no error/exception handling is done]
Die URI or file ending does not matter, it could even be .jpg, there is no default.
Have a look at similiar questions: Does this SOAP Fault mean what I think it means?
It would be helpful if you put the error message into the question, aswell as the XML output of your request.
try setting the SOAP Version in the array of your SoapClient instance to one of the constants (try different ones):
new SoapClient($url, array("soap_version" => SOAP_1_1,.......
or SOAP_1_2 ...
To debug the XML try the answer from Inspect XML created by PHP SoapClient call before/without sending the request
The error message of your updated question does not look like it coming from PHP, looks more like an answer from the webservice, means your request is actually working.
Getting a weird error I have no idea how to fix.
This is the error:
( ! ) Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be an array, string given, called in phar://C:/wamp/www/PHPCodeLance/WebTech/Projects/MIB v2/lib/aws/aws.phar/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php on line 93 and defined in phar://C:/wamp/www/PHPCodeLance/WebTech/Projects/MIB v2/lib/aws/aws.phar/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php on line 113
Call Stack
# Time Memory Function Location
1 0.0009 676280 {main}( ) ..\test.php:0
2 0.0557 3311632 Aws\Ses\SesClient->send_email( ) ..\test.php:30
3 0.0557 3312128 Aws\Common\Client\AbstractClient->__call( ) ..\test.php:30
4 0.0557 3312208 Guzzle\Service\Client->__call( ) ..(null):103
5 0.0557 3312296 Guzzle\Service\Client->getCommand( ) ..(null):93
This is the code I used (straight from the AWS page)
$client = SesClient::factory(array(
'key' => '',
'secret' => '',
'region' => 'us-east-1'
));
$response = $client->send_email(
'no-reply#amazon.com', // Source (aka From)
array('ToAddresses' => array( // Destination (aka To)
'myemail#hotmail.nl'
)),
array( // Message (short form)
'Subject.Data' => 'Email Test ' . time(),
'Body.Text.Data' => 'This is a simple test message ' . time()
)
);
// Success?
var_dump($response->isOK());
UPDATE!!!:
Fixed the issues above, now I got an SSL certificate issue:
Guzzle\Http\Exception\CurlException: [curl] 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [url] https://email.us-east-1.amazonaws.com/ in phar://C:/wamp/www/PHPCodeLance/WebTech/Projects/MIB v2/lib/aws/aws.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php on line 578
Thanks in advance
For an answer to the first (now supposedly resolved - HOW?) issue, see AWS SDK Guzzle error when sending email with SES
Please, if you have a solution to an issue, particularly one as arcane as this, POST IT for others to use.
First of all, it seems that you should include this code for instantiating the client and sending the email within a try-catch block, that will certainly resolve the Catchable fatal error part and allow your code to continue executing.
As far as the getCommand parameter problem, my guess is that there is some issue with your arguments to send_email() that are passed down the call stack. Without digging through the SDK I don;t know off the top of my head what arguments are specifically passed to getCommand, but you have all the information you need there to debug the issue, as you should be able to map how your arguments are passed through each of the calls shown in the stack trace, debugging along the way to verify what is passed to each function is what is expected.
The problem with the SSL is because CURL does not bundle CA certs anymore, you'd need to set the proper CA info.
Solution 1 (Changes to PHP.ini):
Download CA bundle (cacert.pem) from http://curl.haxx.se/docs/caextract.html
Place it on your local system (for eg: C:\xampp\cacert.pem)
Open your php.ini
Set the curl.ca_info options to point to the location of the cacert.pem
Example: curl.ca_info="C:\xampp\cacert.pem"
Restart Apache
Solution 2 (Set options before each CURL call)
Download CA bundle (cacert.pem) from http://curl.haxx.se/docs/caextract.html
Place it on your local system (for eg: C:\xampp\cacert.pem)
Write the following code:
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($ch, CURLOPT_CAINFO, "pathto\cacert.pem");
Source: http://tumblr.wehavefaces.net/post/52114563111/environment-windows-xampp-curl-library
I am trying to perform a Bing Search by using the Windows Azure Marketplace API, I have downloaded their guide and sample code. The code prepares a HTTPS request with basic authentication, however I am constantly getting the following error:
Warning: file_get_contents(https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%27washburn%27&Adult=%27Off%27&$top=50&$format=Atom): failed to open stream: Connection refused
The php code (from Microsoft's document):
$context = stream_context_create(array(
'http' => array(
'proxy' => 'tcp://127.0.0.1:8888',
'request_fulluri' => true,
'header' => "Authorization: Basic " . base64_encode($accountKey.":".$accountKey)
)
));
Does anyone know what is causing the error please? I have correctly set the $accountKey and I tested it in a browser. What puzzles me a little is 127.0.0.1:8888 and also base64_encode($accountKey.":".$accountKey) , how come you need the $accountKey both before and after the : while when using a browser you are supposed to leave the username blank and just input the account key into the password field?
I have solved it and here is what I have found for future people that would be doing the same thing:
I commented out the line where it says:
'proxy' => 'tcp://127.0.0.1:8888',
'request_fulluri' => true,
and also set base64_encode("ignored:".$accountKey) instead
Base on what I read on MSDN, the username part is said to be ignored, so it shouldn't matter what value it is. I was thinking perhaps the length or the special characters in the key screwed things up so I replaces it with ignored (or anything really).
That did the trick and I can parse the returned JSON data. Good luck!
I'm trying to create a web application that will allow a user to post a tweet from a form directly on the webpage, instead of using Twitter's own pre-built pop-up. The problem is, the snippet of code that I'm seeing around the web is not working:
$message = "Hello there! This is a tweet!";
$twitterObj->post('statuses/update', array('status' => "$message"));
And when I try to execute the code I get this error:
Warning: Invalid argument supplied for foreach() in /twitter/EpiOAuth.php on line 76
Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in /twitter/EpiOAuth.php on line 140
I'm building off the example and using the OAuth library found at this web address:
http://www.jaisenmathai.com/articles/twitter-php-sign-in.html
Does anyone have any tips?
EDIT
Problem solved! It turns out that this was the correct statement that I needed to use:
$twitterObj->post_statusesUpdate(array('status' => 'Message goes here.'));
This is what I use:
$message = "Hello there! This is a tweet!";
$twitterObj->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $message), 'POST');
This is with the library found here: https://github.com/abraham/twitteroauth