Not able to connect Firebase with php - wordpress

I am using firebase as backend in php, but when i am calling "fromJsonFile" method of "ServiceAccount" i am getting bellow error:
Fatal error: Uncaught Error: Call to private method
Kreait\Firebase\ServiceAccount::fromJsonFile() from context '' in
C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php:7
Stack trace: #0 C:\xampp\htdocs\wordpress\wp-content\plugins\sb-api\sb_api.php(31):
include() #1 C:\xampp\htdocs\wordpress\wp-settings.php(362):
include_once('C:\xampp\htdocs...') #2
C:\xampp\htdocs\wordpress\wp-config.php(90):
require_once('C:\xampp\htdocs...') #3
C:\xampp\htdocs\wordpress\wp-load.php(37):
require_once('C:\xampp\htdocs...') #4
C:\xampp\htdocs\wordpress\wp-admin\admin.php(34):
require_once('C:\xampp\htdocs...') #5
C:\xampp\htdocs\wordpress\wp-admin\index.php(10):
require_once('C:\xampp\htdocs...') #6 {main}
thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php
on line 7
The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.
Here is my code:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
$database = $firebase->getDatabase();
?>

Can you tell us the version of the firebase-php that you are currently using?
If you are using version lower than 5.x please update to the latest version.
https://github.com/kreait/firebase-php
It is using php 7.2^. Current wordpress requires 7.3 so it must be updated to latest version
Here is the documentation as well.
https://firebase-php.readthedocs.io/en/latest/
I don't know exactly what the problem is but it seems the error says you can't access a private method, so you should access it by updating it to public or public static method.

For ver 5.x
// #see https://firebase-php.readthedocs.io/en/5.2.0/troubleshooting.html
$factory = (new Factory)->withServiceAccount(__DIR__.'/google-service-account.json');
$database = $factory->createDatabase();
// if you want auth
//$auth = $factory->createAuth();

Related

BackoffExceptions are logged at error level when using RetryTopicConfiguration

I am a happy user of the recently added RetryTopicConfiguration there is however a small issue that is bothering me.
The setup I use looks like:
#Bean
public RetryTopicConfiguration retryTopicConfiguration(
KafkaTemplate<String, String> template,
#Value("${kafka.topic.in}") String topicToInclude,
#Value("${spring.application.name}") String appName) {
return RetryTopicConfigurationBuilder
.newInstance()
.fixedBackOff(5000L)
.maxAttempts(3)
.retryTopicSuffix("-" + appName + ".retry")
.suffixTopicsWithIndexValues()
.dltSuffix("-" + appName + ".dlq")
.includeTopic(topicToInclude)
.dltHandlerMethod(KAFKA_EVENT_LISTENER, "handleDltEvent")
.create(template);
}
When the a listener throws an exception that triggers a retry, the DefaultErrorHandler will log a KafkaBackoffException at error level.
For a similar problem it was suggested to use a ListenerContainerFactoryConfigurer yet this does not remove all error logs, since I still see the following in my logs:
2022-04-02 17:34:33.340 ERROR 8054 --- [e.retry-0-0-C-1] o.s.kafka.listener.DefaultErrorHandler : Recovery of record (topic-spring-kafka-logging-issue.retry-0-0#0) failed
org.springframework.kafka.listener.ListenerExecutionFailedException: Listener failed; nested exception is org.springframework.kafka.listener.KafkaBackoffException: Partition 0 from topic topic-spring-kafka-logging-issue.retry-0 is not ready for consumption, backing off for approx. 4468 millis.
Can the log-level be changed, without adding a custom ErrorHandler?
Spring-Boot version: 2.6.6
Spring-Kafka version: 2.8.4
JDK version: 11
Sample project: here
Thanks for such a complete question. This is a known issue of Spring for Apache Kafka 2.8.4 due to the new combine blocking and non-blocking exceptions feature and has been fixed for 2.8.5.
The workaround is to clear the blocking exceptions mechanism such as:
#Bean(name = RetryTopicInternalBeanNames.LISTENER_CONTAINER_FACTORY_CONFIGURER_NAME)
public ListenerContainerFactoryConfigurer lcfc(KafkaConsumerBackoffManager kafkaConsumerBackoffManager,
DeadLetterPublishingRecovererFactory deadLetterPublishingRecovererFactory,
#Qualifier(RetryTopicInternalBeanNames
.INTERNAL_BACKOFF_CLOCK_BEAN_NAME) Clock clock) {
ListenerContainerFactoryConfigurer lcfc = new ListenerContainerFactoryConfigurer(kafkaConsumerBackoffManager, deadLetterPublishingRecovererFactory, clock);
lcfc.setBlockingRetriesBackOff(new FixedBackOff(0, 0));
lcfc.setErrorHandlerCustomizer(eh -> ((DefaultErrorHandler) eh).setClassifications(Collections.emptyMap(), true));
return lcfc;
}
Please let me know if that works for you.
Thanks.
EDIT:
This workaround disables only blocking retries, which since 2.8.4 can be used along non-blocking as per the link in the original answer. The exception classification for the non-blocking retries is in the DefaultDestinationTopicResolver class, and you can set FATAL exceptions as documented here.
EDIT: Alternatively, you can use the Spring Kafka 2.8.5-SNAPSHOT version by adding the Spring Snapshot repository such as:
repositories {
maven {
url 'https://repo.spring.io/snapshot'
}
}
dependencies {
implementation 'org.springframework.kafka:spring-kafka:2.8.5-SNAPSHOT'
}
You can also downgrade to Spring Kafka 2.8.3.
As Gary Russell pointed out, if your application is already in production you should not use the SNAPSHOT version, and 2.8.5 is out in a couple of weeks.
EDIT 2: Glad to hear you’re happy about the feature!

email working on local server but not working on live server AWS using zf3

Description: sending mail from localhost mail working but sending from AWS server mail not working giving error below as i mentioned.
Code:
$options = new SmtpOptions();
$options->setHost('smtp.gmail.com')
->setName('smtp.gmail.com')
->setPort(587)
->setConnectionClass('login')
->setConnectionConfig(array(
'username' => 'user#domain.com',
'password' => '123456789',
'ssl' => 'tls',
'host'=>'333.333.333.333',
'use_complete_quit' => false,
)
);
$transport->setOptions($options);
$res = $transport->send($message);
Error:
An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\Mail\Protocol\Exception\RuntimeException
File:
/var/www/vendor/zendframework/zend-mail/src/Protocol/AbstractProtocol.php:348
Message:
5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuo
5.7.14 Px2wvtfOrS5wFFQmXT6hEwb6_1qcc1hT6WbEWXyUx_ySCaHzuDAWuVXje2HQlktgHPhwIi
5.7.14 8qrKNzgRYBckbmSR5J6_w5JDU5MJHcE-dHh718s0BTmxnsRPpHm970TwgImXzT> Please
5.7.14 log in via your web browser and then try again.
5.7.14 Learn more at
5.7.14 https://support.google.com/mail/answer/78754 a9sm10567779iod.76 - gsmtp
Stack trace:
#0 /var/www/vendor/zendframework/zend-mail/src/Protocol/Smtp/Auth/Login.php(78): Zend\Mail\Protocol\AbstractProtocol->_expect(Array)
#1 /var/www/vendor/zendframework/zend-mail/src/Protocol/Smtp.php(222): Zend\Mail\Protocol\Smtp\Auth\Login->auth()
#2 /var/www/vendor/zendframework/zend-mail/src/Transport/Smtp.php(401): Zend\Mail\Protocol\Smtp->helo('smtp.gmail.com')
#3 /var/www/vendor/zendframework/zend-mail/src/Transport/Smtp.php(383): Zend\Mail\Transport\Smtp->connect()
#4 /var/www/vendor/zendframework/zend-mail/src/Transport/Smtp.php(394): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#5 /var/www/vendor/zendframework/zend-mail/src/Transport/Smtp.php(251): Zend\Mail\Transport\Smtp->connect()
#6 /var/www/module/Application/src/Controller/PurchaseController.php(785): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message))
#7 /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(78): Application\Controller\PurchaseController->orderPlaceAction()
#8 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(106): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#11 /var/www/vendor/zendframework/zend-mvc/src/DispatchListener.php(138): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#12 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#13 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#14 /var/www/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#15 /var/www/html/index.php(54): Zend\Mvc\Application->run()
#16 {main}
Well if you check the support page for error code 78754 of google, they mentions few possible problems.
If you're sure about your mail and password, please be sure you don't request too frequently. They says you shouldn't make request more than 10 minutes.
Also if you're using 2-steps verification, you will need to create application based password or you'll have to use oAuth to access gmail.
I suggest you read this this article too.

Fatal error - Parse error: syntax error, unexpected ':', expecting - Wordpress

I need your help.
I'm trying to install ACF plugin and give me this error:
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /home/htb/mysite/wp-content/plugins/acf-for-woocommerce/vendor/catsplugins/cp-core/src/common/class-cp-util.php on line 23
This is the line 23:
public static function pathToUrl(string $path): string {
Here's the code:
<?php
namespace CastPlugin;
if (class_exists('CpUtil')) {
return;
}
class CpUtil
{
public static function startsWith($haystack, $needle)
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
public static function contains($haystack, $needle)
{
return strpos($haystack, $needle) !== false;
}
public static function pathToUrl(string $path): string {
$ssl = #$_SERVER['HTTPS'];
$serverName = $_SERVER['SERVER_NAME'];
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
$correctPath = $path;
$uri = str_replace($documentRoot, '', $correctPath);
$protocol = $ssl === 'on' ? 'https' : 'http';
return "$protocol://$serverName$uri";
}
}
Any idea how to solve this?
Thank you. :)
The version of ACF you're using requires PHP 7.0+. The error message you're getting indicates you're using PHP 5.6 or older. You should talk to your hosting provider about allowing you to upgrade to newer version of PHP.
This error specifically is caused by a new PHP method declaration syntax introduced in PHP 7.0 that allows you to declare that the method you're defining will return an array, which you can read about here: http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration
If your hosting provider won't upgrade your PHP version, I suggest you find a new hosting provider. But if you need ACF to work in the meantime, you can go to the advanced page for ACF in the repository and download an older version at the bottom of the page.
Note: Both of these practices (using an outdated PHP version and using an outdate plugin) can be detrimental to the long-term health of your WordPress installation. I'd recommend getting on to PHP 7.2 at least as soon as you're able, which will allow you to use the most recent version of ACF.

PHPUnit\Framework\Error\Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

I'm following zend's tutorial to use zend-test on my project, but I'm getting this error.
To build my project's base I did the biggest part of this book.
I'm also using PHP 7.2.
When I search google I found a lot of people having trouble using PHP 7.2 with PHP Unit, but it looks like it's ok by now. Did zend-test also being update? If no, what can I do to use zend-test by now? If yes, how do I get the last version?
EDIT
After some test I found the problem, it is on the bootstrap function:
public function onBootstrap( MvcEvent $event ) {
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$sessionManager = $serviceManager->get(SessionManager::class);
$eventManager = $event->getApplication()->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
// Registra o método fo event listener
$sharedEventManager->attach(AbstractActionController::class,
MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 100);
// Caso a sessão não seja válida, esquece ela
$this->forgetInvalidSession($sessionManager);
}
To be more specific, the problem starts at this line:
$sessionManager = $serviceManager->get(SessionManager::class);
EDIT 2
Removing that line e it's uses, it kind than work, but starts to give the same error in another module in a similar line:
$authService = $container->get(\Zend\Authentication\AuthenticationService::class);

ODBC connection on a wordpress site

I am trying to make a localhosted WordPress site use the ODBC connections I use for business analytics.
I made a plugin and am trying to reference the functions in shortcode (because this is the only way I know to do this).
Below is my code:
$dsn = '****';
$user = '****';
$pw = '****';
$connect = odbc_connect($dsn, $user, $pw);
if ($connect == true){
echo '<br> connected <br>';
} else{
echo '<br> not connected <br>';
}
From what I understand this should be testing to see if the connection is open and it gives me an error (posted below). My big question is if I need to install an ODBC driver on the site to make it able to perform the connection.
If so, where do I find this?
I use four MS SQL servers on the domain and would also like to be able to work with access and excel.
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
in
C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php:54
Stack trace:
#0 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(326):HPM_API_E2('', '', 'HPM_API_E2')
#1 [internal function]: do_shortcode_tag(Array)
#2 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(223):preg_replace_callback('/\\[(\\[?)(HPM_AP...','do_shortcode_ta...','[HPM_API_E2]\n[H...')
#3 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\plugin.php(235):do_shortcode('[HPM_API_E2]\n[H...')
#4 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\post-template.php(240):apply_filters('the_content', '[HPM_API_E2]\n[H...')
#5 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\themes\generatepress\content-page.php(24):the_content()
#6 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\template.php(574):require('C:\\Bitnami\\word...')
#7 C:\Bitnam in C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php on line 54
$connect will never be true. This is because odbc_connect() does not return a boolean when it succeeds. It returns a connection IDinstead.
If the connection fails it will return an error or false, so it will end up in the else. If it succeeds it contains an ID and should evaluate to true.
if ($connect){
echo '<br> connected <br>';
} else{
echo '<br> not connected <br>';
}
Edit:
You've just added the error message you're getting. That error means the function is not available, and that will most likely be caused by the missing ODBC drivers for your php client. Someone else made this post on how to install this:
Call to undefined function odbc_connect() message while connecting SAP Hana database
I hope this helps.

Resources