Twilio Client Conference Call Monitor incomplete output with PHP error - php

Trying to implement the Twilio Client Conference Call Monitor as described here:
https://www.twilio.com/docs/howto/twilio-client-browser-conference-call-monitor
It "sees" ongoing conferences and has output like this:
Found 0 conference(s)
Found 1 conference(s)
etc.
However, it doesn't list the ongoing conferences as desired. No further output is given.
In the ssl_error_log, I found this, which is interesting:
PHP Fatal error: Uncaught exception 'Exception' with message 'Objects
returned by Services_Twilio_Page::getIterator() must be traversable or
implement interface Iterator' in /mypath/call_monitor.php:74\nStack
trace:\n#0 /mypath/call_monitor.php(74): unknown()\n#1 {main}\n
thrown in /mypath/call_monitor.php on line 74
I don't find any results here or on Google for this message, so I'm thinking it's particular to my setup.
I'm using Linux / Apache / PHP Version 5.2.17.

The support team at Twilio advised the following:
...it looks like there's a bug in the example code. Can you change
this:
$conferences = $client->account->conferences->getPage(0, 50, array('Status' => 'in-progress'));
to:
$conferences = $client->account->conferences->getIterator(0, 50, array('Status' => 'in-progress'));
i.e. change "getPage" to "getIterator" ?
This corrected the error I reported, but introduced other issues not within the scope of this question.

Related

How can I determine why a PHP 'Exception' is suddenly of type 'Error' instead?

I don't know PHP. I have some PHP code written about 15 years ago by someone other than me. It has suddenly started throwing a fatal error
PHP Fatal error: Uncaught TypeError: Argument 1 passed to ReportException() must be an instance of Exception, instance of Error given
The stack trace shows a function ReportException() that takes an Exception:
function ReportException( Exception $e ) {
...
}
This function is called by another function ExceptionHandler() that takes an argument with no declared type, but which is presumed to be an Exception:
function ExceptionHandler( $e ) {
ReportException( $e );
...
}
The problem is, no other line in the code base calls ExceptionHandler(), so I can't trace where $e is being passed from to see why it's now an Error type instead of an Exception type.
There is this:
/**
* Install an exception handler.
*/
function InstallExceptionHandler() {
set_exception_handler( 'ExceptionHandler' );
}
which, when called (which it is), seems to set the ExceptionHandler() function as a general sort of Exception Handler. Not knowing PHP, though, I don't know how to follow this up further.
How can I determine why $e is coming to ExceptionHandler() as an Error instead of an Exception? I'm especially interested in answers that can suggest a testable theory about why this is suddenly an issue after the program has worked just fine for ~15 years. It's currently running on PHP 7.4.3, but I don't know what version it was written for.
Update
Barmar and Sammitch's suggestion to change the type of $e from Exception to Throwable causes the Fatal Error not to appear anymore. However, the app still does not work, so I can't say for certain that that's a full solution yet. I'll update when I know more.
Update 2
The app suddenly started working again, and with no fatal error. Ready to accept an answer.

Amazon cloudsearch describedoamin usage

I am trying to use describeDomains function of AWS CloudSearch. But I am getting the below error.
exception 'ReflectionException' with message 'Method Aws\CloudSearch \CloudSearchClient::describeDomains() does not exist
You've probably already figured this out by now, but I think you just need to fix the casing of the DescribeDomains() method (note the initial capital D).
See PHP SDK documentation:
https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cloudsearch-2013-01-01.html#describedomains

Google_Http_MediaFileUpload constructor must implement interface Psr\Http\Message\RequestInterface

I am trying to upload large files in newly created folder in google drive via php .
but when I am not using
$client->setDefer(true);
Then I am getting this error:
Catchable fatal error: Argument 2 passed to Google_Http_MediaFileUpload::__construct() must implement interface Psr\Http\Message\RequestInterface, instance of Google_Service_Drive_DriveFile given, called in /var/www/html/google_drive2/gdrive_upload.php on line 158 and defined in /var/www/html/google_drive2/src/Google/Http/MediaFileUpload.php on line 78
And when I use
$client->setDefer(true);
Then i get this:
Uncaught exception 'Google_Service_Exception' with message 'Not Found' in /var/www/html/google_drive2/src/Google/Http/REST.php on line 118
( ! ) Google_Service_Exception: Not Found in /var/www/html/google_drive2/src/Google/Http/REST.php on line 118
Tried everything but fails. please tell what I am doing wrong.
Here is my complete code of gdrive_upload.php
https://pastebin.com/x96CZg3U
The error:
Google_Service_Exception: Not Found in /path/to/src/Google/Http/REST.php on line 118
occurs when you are passing an invalid reference to the Google API and the API cannot find the resource you are requesting.
For example, when adding a file to Google Drive, this will show when an invalid Google Drive Id is passed.
When adding an event to Google Calendar, this will show when an invalid Google Calendar Id is passed.
Etc.
In your case, the folder is probably not fully set up yet. So you are using a valid Id, but Google has not fully created the folder. Using $client->setDefer(true) probably allows Google enough time to fully set up the folder, which allows your folder Id to validate.
Disclaimer: This error quite possibly appears for other circumstances as well.

SOAP: HTTP Not Found when parameter is "SELECT sth FROM"!

I' ve a problem with Soap (I'm using it for the first time!).
I'm trying to solve a problem with SOAP, used to communicate between my site and another.
In SoapServer (on my site) I have a function called say_hello() that takes no argument and returns simply "hello", if I call it from a SoapClient, also with an argument, it works well.
The problem appears if the argument passed is "SELECT everythingyouwanthere FROM otherthingifyouwant". I don't know why but it returns "PHP Fatal error: Uncaught SoapFault exception: [HTTP] Not Found" (404 error).
This started to happen suddenly (or, at least, I don't know the causes). On the server PrestaShop is installed.
Thanks in advance!
P.S. Sorry for my bad english!
try to pass the argument through an array.
Instead of
...
$client = new SoapClient(WSDL);
$client->say_hello("SELECT everythingyouwanthere FROM otherthingifyouwant");
...
try
...
$client = new SoapClient(WSDL);
$client->say_hello(array("parameter_name" => "SELECT everythingyouwanthere FROM otherthingifyouwant"));
...

Get Monolog JSON Stack Trace as Array

I'm using Laravel 4.2 and want to get logs out as JSON. Laravel uses Monolog, so I've configured the JSON formatter like so:
$logHandler = new Monolog\Handler\StreamHandler(Config::get('app.logFile'), Monolog\Logger::DEBUG);
$logHandler->setFormatter(new Monolog\Formatter\JsonFormatter);
Log::getMonolog()->pushHandler($logHandler);
The problem is that stack traces are included as part of the message string, like so:
{
"message": "exception 'Exception' with message 'Socket operation failed: Host name lookup failure' in /var/www/vendor/clue/socket-raw/Socket/Raw/Socket.php:388\nStack trace:\n#0 /var/www/vendor/clue/socket-raw/So..."
}
Can someone point me in the right direction to make the stack trace its own separate array in the json?
Long overdue update:
The primary problem is that Laravel, and lots of code following its example, tries to log the exception by itself, e.g., Log::error($e). This is the wrong way to log an exception with Monolog. That first parameter is supposed to be a simple message string. In processing it, Monolog\Logger::addRecord() explicitly casts the message to a string:
$record = array(
'message' => (string) $message,
//...
);
If $message is actually an exception, you get the whole stack trace as a string. Unfortunately, this is what Laravel's default exception handler does.
The correct way to get a stack trace as an array is to pass the exception in as context so that it's available non-stringified to the formatter. For instance:
Log::error($e->getMessage(), ['exception' => $e]);
Something equivalent is what you need to put in your custom exception handler for Laravel, and then you can use a proper JSON formatter and get what you except.

Categories