I am developing a Laravel-5.4 application that connect to some outlook/Hotmail mailbox using imap. From time to time (about 30%) i get this error when i try to connect using:
try {
$imap_open = imap_open($this->imapPath . $this->folder, $this->username, $this->password, OP_READONLY) or die('Cannot connect to : ' . $this->imapPath . ' ' . imap_last_error());
} catch (\Exception $e) {
$output = new ConsoleOutput();
$output->writeln('Imap Connect Exception : ' . $e->getMessage());
}
Note: imapPath and username and password are hard coded so they remain the same in every request.
The error is not catchable by try_catch, so it block my entire request.
The error i get is:
[Thu Apr 27 12:39:08 2017] PHP Fatal error: Uncaught exception 'ErrorException'
with message 'Unknown: [CLOSED] IMAP connection broken (server response) (errfl
g=2)' in Unknown:0
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handle
Error(8, 'Unknown: [CLOSE...', 'Unknown', 0, Array)
#1 {main}
thrown in Unknown on line 0
what i want is to catch this Exception or Error if that is possible so i can re-connect again to the mailbox when the connection is broken.
Related
I am new to SOAP API and WSDL. I had this project to use the SOAP API and I used this code from one of the stackoverflow answers. But when I am running this, I am getting this error.
Fatal error: Uncaught SoapFault exception: [HTTP] Forbidden in 'directory' Stack trace: #0 [internal function]: SoapClient->__doRequest('...') #1 directory): SoapClient->__call('method', Array) #2
Here is my code:
<?php
try{
$wsdl_url = 'API';
$client = new SoapClient($wsdl_url);
} catch (SoapFault $e) {
echo 'Error in Soap Connection : '.$e->getMessage();
}
$params = array(
'LBID' => '1',
'YearID' => '23',
'SectorId' => '3',
'Password' => 'password'
);
$result= $client->getProjectDetails($params);
print_r($result);
?>
I am able to access the api by directly putting it on address bar. The soap connection is established, no errors there. But this error is showing on the method calling line, $result= $client->getProjectDetails($params);
I don't know what this error is, I tried searching the forums but couldn't get any idea about this. Can anyone help?
Im new to Five9 i got some sample code in GitHub (https://github.com/kielerrr/Five9 ) which i went though the code and i passed the credentials into API but i get the following error
"Fatal error: Uncaught Error: Class 'SoapClient' not found in C:\xampp\htdocs\Five9-master\includes\Five9.php:20 Stack trace: #0 C:\xampp\htdocs\Five9-master\contacts\getContactRecords.php(12): f9->__construct() #1 {main} thrown in C:\xampp\htdocs\Five9-master\includes\Five9.php on line 20"
$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl&user=User_ID";
//$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl";
try {
$soap_options = array('login' => 'uer_name', 'password' => 'mypassword', 'trace' => true);
$this->_connection = new SoapClient($wsdl_five9, $soap_options);//20th line
} catch (Exception $e) {
$error_message = $e->getMessage();
echo $error_message."ERROR";
exit;
}
Please help me to go through this ...
The Above code works fine need to enable soap in your system .
locate your php.ini file and Un-comment(remove semicolon before soap extension)as below.
change from :
";extension=php_soap.dl"
to :
"extension=php_soap.dll" .
I am trying to connect to a node server using ElephantIO in php
Here is the code
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
use ElephantIO\Client,
ElephantIO\Engine\SocketIO\Version1X,
ElephantIO\Exception\ServerConnectionFailureException;
require __DIR__ . '/vendor/autoload.php';
$client = new Client(new Version1X('http://localhost:3001'));
try
{
$client->initialize();
$client->emit('new_order', ['foo' => 'bar']);
$client->close();
}
catch (ServerConnectionFailureException $e)
{
echo $e;
}
And i am getting an error on connection
ElephantIO\Exception\ServerConnectionFailureException: An error occurred while trying to establish a connection to the server in /var/www/html/Socket/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php:167 Stack trace: #0 /var/www/html/Socket/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php(48): ElephantIO\Engine\SocketIO\Version1X->handshake() #1 /var/www/html/Socket/vendor/wisembly/elephant.io/src/Client.php(60): ElephantIO\Engine\SocketIO\Version1X->connect() #2 /var/www/html/Socket/emit_test.php(47): ElephantIO\Client->initialize() #3 {main}
I am trying to get Mink working on Centos/Apache, but it cannot connect. I have tried with Selenium2Driver, ZombieDriver and last Sahi but I always get a different error.
Right now with Sahi:
require __DIR__ . '/vendor/autoload.php';
$driver = new \Behat\Mink\Driver\SahiDriver('firefox');
$session = new \Behat\Mink\Session($driver);
$session->start();
$session->visit('http://google.it');
echo $session->getStatusCode();
and generate this error:
Fatal error: Uncaught exception 'Buzz\Exception\RequestException' with
message 'couldn't connect to host' in
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php:29
Stack trace: #0
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(130):
Buzz\Client\Curl->send(Object(Buzz\Message\Request),
Object(Buzz\Message\Response)) #1
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(82):
Buzz\Browser->send(Object(Buzz\Message\Request)) #2
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(36):
Buzz\Browser->call('http://localhos...', 'POST', Array, '') #3
/var/www/html/Test/vendor/behat/sahi-client/src/Connection.php(268):
Buzz\Browser->post('http://localhos...', Array, '') #4
/var/www/html/Test/vendor/behat/sahi-client/src/Connection.php(150):
Behat\SahiClient\Connection->post('http://localhos...') #5
/var/www/html/Test/vendor/behat/sahi-client/src/Client.php( in
/var/www/html/Test/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php
on line 29
I have installed with composer:
behat/behat
behat/mink
behat/mink-sahi-driver
behat/sahi-client
Why it cannot connect?
I have this block:
try {
$this->dbh = new PDO(
"mysql:host=".appparams::dBHost.
";port=".appparams::dBPort.
";dbname=".appparams::dBName.
";charset=utf8",
appparams::dBUser,
appparams::dBPassword,
array(
PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'",
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
)
);
$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); #line 36
$this->dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
trigger_error("501", E_USER_ERROR);
}
If, for example, I shutdown mysql, I get this on error_log when executing the code:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /var/www/myweb/mypage/db.php:36\nStack trace:
#0 /var/www/myweb/mypage/db.php(36): PDO->__construct('mysql:host=loca...', 'root', 'my_database_password!!!', Array)
#1 /var/www/myweb/mypage/accesslogmapcontroller.php(84): myweb\\db->__construct()
#2 /var/www/myweb/mypage/main.php(54): myweb\\accesslogmapcontroller::process('READ', Array)
#3 /var/www/myweb/mypage/main.php(179): myweb\\main::main()
#4 {main}\n thrown in /var/www/myweb/mypage/db.php on line 36, referer: http://mydomain.com/myweb/mypage/
As #Jon said:
#elcodedocle: It's definitely the namespace if you have not imported PDOException. catch (\PDOException $e) instead and it should work.
(An obvious issue but a little confusing output: "Undefined exception" would be much more helpful to debug this...)