I'm using HttpRequest and HttpRequestPool to send parallel http requests, the number of requests is up to 200 or something, the thing is that some of the receivers might be offline, so that HttpRequestPool::send() will wait until it gets a response or until it times out.
Example of usage:
$query = "CALL GetBoardsURLS()";
$result = mysql_query($query) or die("ERROR:QUERY_FAILED 8" . mysql_error());
$pool = new HttpRequestPool();
//Add the data to the request pool.
while($row = mysql_fetch_row($result))
{
$req = new HttpRequest($row[0].'/', HTTP_METH_POST);
$req->setBody($message);
$pool->attach($req);
}
$pool->send();
In my php error log i get errors, can someone tell me what I have to do to avoid them? I'm guessing that this happens mostly because of timed out requests to invalid destinations, becaues all receivers that are valid do get the message and act accordingly.
Any suggestions?
Ty in advance.
**ERRORS**:
[13-Nov-2012 14:20:00 UTC] PHP Fatal error: Uncaught exception HttpRequestPoolException' with message 'Exception caused by 2 inner exception(s)' in C:\inetpub\wwwroot\DeusTesting\TimeSet.php:130
inner exception 'HttpInvalidParamException' with message 'Empty or too short HTTP message: ''' in C:\inetpub\wwwroot\DeusTesting\TimeSet.php:0
inner exception 'HttpRequestException' with message 'Timeout was reached; Connection time-out (http://sim6261.agni.lindenlab.com:12046/cap/11b23456-63bd-1c56-8692-b640ac992a76/)' in C:\inetpub\wwwroot\DeusTesting\TimeSet.php:130
Stack trace:
#0 C:\inetpub\wwwroot\DeusTesting\TimeSet.php(0): HttpRequestPool->send()
#1 {main}
thrown in C:\inetpub\wwwroot\DeusTesting\TimeSet.php on line 130
[13-Nov-2012 14:30:03 UTC] PHP Fatal error: Uncaught exception 'HttpRequestPoolException' with message 'Exception caused by 12 inner exception(s)' in C:\inetpub\wwwroot\DeusTesting\TimeSet.php:130
Okay, this question was around here for a while and not answered. So I'll say what I did to get rid of the errors.
$pool = new HttpRequestPool();
//Add the data to the request pool.
foreach($boardsURLS as $boardURL)
{
$req = new HttpRequest($boardURL.'/', HTTP_METH_POST);
$req->setBody($message);
$req->setOptions(array('connecttimeout' => 3, 'timeout' => 3));
$pool->attach($req);
}
$ErrorLog = fopen('Logs/GameEnd.txt', "a+");
try
{
$pool->send();
}
catch(HttpException $ex)
{
fprintf($ErrorLog, '%s', $ex);
}
fclose($ErrorLog);
The "errors" were exceptions, and since I didn't handle them they were added in the php53_errors.log. Now by adding try and catch, the exceptions could be handled so that solved it. Now I store the exceptions(timeout exceptions) in a separate file (that's because i wanted to) someone else can handle them differently of course. So not much I can do about it.
NEXT
$req->setOptions(array('connecttimeout' => 3, 'timeout' => 3));
This is the part I like. Since I don't really care about the response, I just want my http requests to get transmited to the receivers. I put a timeout of 3 seconds. That prevents my script from keep running and waiting for the responses.
Hope this will help someone. Cheers
Related
I am using SOAP in a php script to call a web service from a Linux Centos 6 server. In this week I have been getting could not connect to host error from soapCall method. Of course this exception does not happen all the time but I see this exception most of the time, for example if I call soapCall 5 times, this error happens 3 times. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I have read most answers to related questions here but my problem has not been solved. Also I added
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl","0");
but nothing changed. I searched a lot about the reason and I found something about SSL but I have not found exact solution.
It must be mentioned that I can see the wsdl URL in browser and I have it's ping.
I have this code:
require_once dirname(__FILE__)."/Chat-API-master/src/Registration.php";
$username = '972********'; // Your number with country code, ie: 34123456789
$nickname = 'A****'; // Your nickname, it will appear in push notifications
$debug = true; // Shows debug log, this is set to false if not specified
$log = true; // Enables log file, this is set to false if not specified
$dst = '+9725******';
$code = '17****';
$password="";
//$w = new WhatsProt($username, $nickname, $debug, $log);
$r = new Registration($username, $debug);
//$r->codeRequest('sms'); // could be 'voice' too
//$result=$r->codeRequest('sms'); // could be 'voice' too
$r->codeRegister($code);
I took the library from this link:
https://github.com/WHAnonymous/Chat-API/wiki/WhatsAPI-Documentation
I applied the code execution as it is described. I receieved the SMS, then I used the register function, and I got this error.
Fatal error: Uncaught exception 'Exception' with message 'An error occurred registering the registration code from WhatsApp. Reason: missing' in C:\xampp\htdocs\WhatsUp\Chat-API-master\src\Registration.php:181 Stack trace: #0 C:\xampp\htdocs\WhatsUp\index.php(19): Registration->codeRegister('175746') #1 {main} thrown in C:\xampp\htdocs\WhatsUp\Chat-API-master\src\Registration.php on line 181
The response that I should be getting is a password (parameter that is called 'pwd'). I also used their two tools that are described in the link.
You can also use WART, you can download from here: /mgp25/WART
Or you can use this online tool: watools
The picture below shows the response that I got.
enter image description here
Why am I getting those errors. Where does this code go wrong? and if the framework doesnt work! what framework is there that works well?
I just need a simple code that sends a simple whatsapp message.
Recently I tried to use OpenTok's WebRTC demo for a web application requiring peer-to-peer video/audio communication.
I went through the tutorials on http://www.tokbox.com/opentok/webrtc/docs/js/tutorials/ and http://www.tokbox.com/opentok/docs/server/server_side_libraries.html and I got something working using JavaScript (client-side) and PHP's library (server-side) for token/session generation.
I managed to code a basic peer-to-peer chat room locally. However, as soon as I upload it to a web server it blows up returning the following error:
Fatal error: Uncaught exception 'RequestException' with message 'Request error: Failed
to connect to 70.42.47.98: Permission denied' in /home/www/dummy_url.com/php-
sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php:192 Stack trace: #0 /home/www/dummy_url.com/php-
sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php(107): OpenTokSDK->_do_request('/session/create',
Array) #1 /home/www/dummy_url.com/php-sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php(221):
OpenTokSDK->createSession('74.96.245.119', Array) #2 /home/www/dummy_url.com/php-
sdk/index.php(16): OpenTokSDK->create_session('74.96.245.119', Array) #3 {main} thrown
in /home/www/dummy_url.com/php-sdk/SDK/Opentok-PHP-SDK/OpenTokSDK.php on line 192
I took a look at line 192:
//die(function_exists('curl_version')); // debugging
$res = curl_exec($ch);
if(curl_errno($ch)) {
throw new RequestException('Request error: ' . curl_error($ch)); // <=== LINE 192
}
curl_close($ch);
and verified the server had curl enabled. It does.
Then I tried to run the demo test and it fails at:
Assertion Failed: File '/home/www/skillfullearning.net/test/test/TestOpenTokSDK.php'
Line '102'
Code ''
What's in Line '102'? This:
...
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() + 100000);
assert('$token');
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime());
assert('$token');
try {
$token = $a->generateToken("mysession", RoleConstants::MODERATOR, gmmktime() +
1000000);
assert(false);
} catch (Exception $e) {
assert('$e'); // <================ LINE 102
}
...
I really don't know where to go from here. I would really appreciate some help with this matter.
/E
The error is caused by outdated tests. Here is an outstanding issue, hopefully it will be resolved soon. if you simply remove the test files, you would not have that problem anymore.
I am processing a huge xml document (which contains around a million entries) and subsequently importing a formatted version to the db using rabbitmq. Each time after publishing around 200,000 entries I receive a broken pipe error , and rabbitmq is unable to recover from it.
Notice Error: fwrite(): send of 2651 bytes failed with errno=11
Resource temporarily unavailable in
[/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc, line
439]
Notice Error: fwrite(): send of 33 bytes failed with errno=104
Connection reset by peer in
[/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc, line
439]
Notice Error: fwrite(): send of 19 bytes failed with errno=32 Broken
pipe in [/var/www/ribbon/app/Console/Command/lib/php_amqplib/amqp.inc,
line 439]
This subsequently causes a node down error and the process needs to be manually killed to recover from it.
These are my class methods:-
public function publishMessage($message) {
if (!isset($this->conn)) {
$this->_createNewConnectionAndChannel();
}
try {
$this->ch->basic_publish(
new AMQPMessage($message, array('content_type' => 'text/plain')),
$this->defaults['exchange']['name'],
$this->defaults['binding']['routing_key']
);
} catch (Exception $e) {
echo "Caught exception : " . $e->getMessage();
echo "Creating new connection.";
$this->_createNewConnectionAndChannel();
$this->publishMessage($message); // try again
}
}
protected function _createNewConnectionAndChannel() {
if (isset($this->conn)) {
$this->conn->close();
}
if(isset($this->ch)) {
$this->ch->close();
}
$this->conn = new AMQPConnection(
$this->defaults['connection']['host'],
$this->defaults['connection']['port'],
$this->defaults['connection']['user'],
$this->defaults['connection']['pass']
);
$this->ch = $this->conn->channel();
$this->ch->access_request($this->defaults['channel']['vhost'], false, false, true, true);
$this->ch->basic_qos(0 , 20 , 0); // fair dispatching
$this->ch->queue_declare(
$this->defaults['queue']['name'],
$this->defaults['queue']['passive'],
$this->defaults['queue']['durable'],
$this->defaults['queue']['exclusive'],
$this->defaults['queue']['auto_delete']
);
$this->ch->exchange_declare(
$this->defaults['exchange']['name'],
$this->defaults['exchange']['type'],
$this->defaults['exchange']['passive'],
$this->defaults['exchange']['durable'],
$this->defaults['exchange']['auto_delete']
);
$this->ch->queue_bind(
$this->defaults['queue']['name'],
$this->defaults['exchange']['name'],
$this->defaults['binding']['routing_key']
);
}
Any help will be appreciated.
Make sure you have added virtualhost access for your user on Rabbit MQ. I've created new user and forgot set access rights for "/" host which is used by default.
You can do that via management panel yourhost:15672 > Admin > click on user > Look for "Set permission".
P.S. I assume your RabbitMQ service is running, user exists and password is correct.
Actually this problem happens when you have a big content inside your message and your consumer expend too much time to process only one message, that is problem to response "ACK" to rabbit and try to consume another message.
When I have this problem for example I try to "fit" my messages, because its a products worker and each message had some like 1k products id, so I change to 100 products and it works very well.
You can read more about Detecting Dead TCP Connections with Heartbeats here
This problem happened to me when my connection to RabbitMQ was broken (the reason does not matter, in my case I intentionally stopped RabbitMQ service for some failure tests), and I was trying to reconnect to the RabbitMQ again by closing the old connection and initializing a new one, but I received Broken pipe or closed connection error.
The way I solved this problem was to use reconnect() method on my connection:
$channel->reconnect();
I make use of a great class made by Jaisen: http://github.com/jmathai/twitter-async/tree/master. Recently twitter has been up and down and I am sure it will continue to be the same in the future so I am trying to cut down on my dependency on twitter being actually working.
The following is what I have in my header.php and it is right at the top and it generates the login URL for each user. If twitter is down, my site hangs for as long as it needs to and it throws an exception. So I have to catch these expceptions which I have sort of done.
I now want to just cancel the request to the API after a few seconds and just load the page and keep trying behind the scenes. How can I best do this?
<?php include './twitter/EpiCurl.php'; include './twitter/EpiOAuth.php'; include './twitter/EpiTwitter.php';
$consumer_key = 'mykey';
$consumer_secret = 'mysecret';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
try{
$twiturl = $twitterObj->getAuthenticateUrl();
$url = "window.open('".$twiturl."','Login', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=1'); startLoad();";
}catch(EpiOAuthBadRequestException $e){
// bad request exception do something
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthUnauthorizedException $e){
// bad authorization..probably bad tokens, do something different
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthException $e){
// uh oh, unknown oauth exception
$statusMessage = 'Oops, an unknown authorisation error has occurred! The mojo team have been notified! Please try again.';
}
if(isset($statusMessage)){
}
?>
Any improvement of the above code will also be appreciated.
Thanks all
The library supports a value to be passed into the curl timeout.
$twitterObj->setTimeout($secs_request_timeout);
I just added support for passing in a connection timeout as well. Unable to run unit tests because I'm being rate limited. Will commit this once I can verify that it works.
$twitterObj->setTimeout($secs_request_timeout, $secs_connection_timeout);
Use curl_setopt(CURLOPT_CONNECTTIMEOUT, 1 /* 1 second timeout */); to cause CURL to give up if a connection isn't established in 1 second. I use this when connecting to the facebook API, 'cause they've been pretty unreliable in the past as well.