"Constant CRLF already defined" error when using php-resque with Laravel - php

I'm running php-resque together with Laravel 3 on Ubuntu 12.04.
Problem: When a job is enqueued in resque, I get the following error:
Unhandled Exception
Message:
Constant CRLF already defined
Location:
/var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
What does the error mean and how can we solve it?
PHP
// Enqueue in Resque
$data = array(
'name' => $name,
'email' => $email,
'created_at' => DB::raw('NOW()')
);
Resque::enqueue('queue', 'exampleWorker', $data);
However when I try to enqueue a job using artisan, it works!
Task
class Queue_Task
{
public function run()
{
// Autoload composer vendors.
require path('composer').DS.'autoload.php';
$args = array('name' => 'John Smith');
Resque::enqueue('MyAppName', 'ExampleWorker', $args);
echo "Resque job queued.\n";
return;
}
}
Output
PHP Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Resque job queued.

It's a guess, but I'd say in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php there's a second define('CRLF', 'something') on line 10 that should probably be commented out if you want these two pieces of software to work together.

Related

constant errors using insights Facebook marketing api (php)

I get this error when I try to run my app locally via xampp. Just to note, I generated code using quick start from developers.facebook so there shouldnt be errors within the code itself.
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 83
Warning: fwrite() expects parameter 1 to be resource, string given in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 182
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message '(#100) Filtering field delivery_info is invalid. Please refer to the document https://developers.facebook.com/docs/marketing-api/insights for valid filters.' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php:144 Stack trace: #0 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(162): FacebookAds\Http\Request->execute() #3 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(204): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 C:\xampp\htdocs\working\vendor\facebo in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php on line 144
I'm starting to suspect that I got the wrong files from the composer. or there might be a problem with my setup. The contents of my composer.json just before I ran composer.phar was
{
"require": {
"facebook/php-sdk-v4" : "~5.0",
"facebook/php-ads-sdk": "2.10.*"
}
}
I'm going to attach the code below just in case you guys want to look at it as well. The only thing that I modified there is adding the app_id since it was not included from the generated code.
<?php
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdsInsights;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$app_id = '274807576345457';
$access_token = 'EAAD575ZC4O3EBAChoTmxC0nwdbvjXLRUKGGXgmZA6HZBFjmKZB6F3olMIe2mG2dgQSb9SudtN7EeeO8gzo7zgFZB0EHZAwTrg4wsIKsJxB3bhw5fonZC3YCZA0C4InaCSOgW42i4PswQa3BZCctMZBYTh94TwGLxGg8gZAZAj4zZC5PfgXl0kw6eOuxW4g1L41NOwtRDGS7O7FsJZBWZCM0IAe00WSf';
$ad_account_id = 'act_113902719358005';
$app_secret = 'aeb42f19e0f33f0937c023fff12909c4';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
'cost_per_result',
'cost_per_total_action',
'cpm',
'cpp',
'frequency',
'impressions',
'impressions_auto_refresh',
'impressions_gross',
'reach',
'relevance_score:score',
'relevance_score:positive_feedback',
'relevance_score:negative_feedback',
'result_rate',
'results',
'social_impressions',
'social_reach',
'spend',
'today_spend',
'total_actions',
'total_unique_actions',
'actions:video_view',
'video_10_sec_watched_actions:video_view',
'delivery',
);
$params = array(
'level' => 'campaign',
'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active','limited'))),
'breakdowns' => array(),
'time_range' => array('since' => '2017-09-28','until' => '2017-09-29'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
if comment this part
[json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);]
; the error stop.
if make [var_export((new AdAccount($ad_account_id));] show full array
I experienced the exact same error. I believe (in my case) this was because I was also using an older PHP version (5.6) resulting in some compatibility issues.
I solved this by changing the version of php-ads-sdk from 2.8 to "8.*" (or change it to any recent version according to when you are reading this solution) in composer.json.
Then call sudo composer update in your terminal

Trouble understanding Facebook Uncaught Exception

I'm super new to Facebook PHP SDK. I am having trouble understanding the stack trace below; where should I look for the error?
The Facebook Scheduled posts are successfully processing, however, this error causes a bad user experience, but, everything else in my program is working fine. It looks like it may be trying to process something that isn't there.
The last line of code being executed (I know because the scheduled posts show up in my Facebook Test Account) is:
$responses = $fb->sendBatchRequest(($batch), $this->session->userdata('fb_access_token'));
$batch is defined as:
foreach($esdarr as $key => $event_start_datetime){$sched_time = strtotime($event_start_datetime)- 18000;
$event_end_datetime = $eedarr[$key];
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
$batch[$key]=$requestScheduleEvent;
}
This is all within a CI Controller (event.php) with public function add(). Then I get this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Argument for add() must be of type array or FacebookRequest.' in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php:85 Stack trace:
#0 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(78): Facebook\FacebookBatchRequest->add(Object(Facebook\FacebookResponse), 0)
#1 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php(61): Facebook\FacebookBatchRequest->add(Array)
#2 /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/Facebook.php(492): Facebook\FacebookBatchRequest->__construct(Object(Facebook\FacebookApp), Array, 'EAAYzEGW0ZAsoBA...', 'v2.7')
#3 /home/my_user/public_html/development/application/controllers/user/event.php(777): Facebook\Facebook->sendBatchRequest(Array, 'EAAYzEGW0ZAsoBA...')
#4 [internal function]: Event->add in /home/my_user/public_html/development/application/vendor/facebook/php-sdk-v4/src/Facebook/FacebookBatchRequest.php on line 85
If I change line #85 of FacebookBatchRequest.php as follows (that is; redirect the page to the correct URL within the CI structure), everything seems to work fine:
public function add($request, $name = null)
{
if (is_array($request)) {
foreach ($request as $key => $req) {
$this->add($req, $key);
}
return $this;
}
if (!$request instanceof FacebookRequest) {
***redirect('user/event');***
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
}
$this->addFallbackDefaults($request);
$requestToAdd = [
'name' => $name,
'request' => $request,
];
Of course, this is a tenuous workaround at best. So, I'd like to know why the error is being thrown in the first place.
If you defined add() in your program and add() is also built in to the SDK, it won't work. Try using a different name.
If that isn't the problem, can you please post your code? Perhaps one of us can find it.
What language are you using? Perhaps you just have a syntax error.
I hope this helps in any way!
Okay, this ended up being an erroneous use of the batch process on my part.
$requestScheduleEvent = $fb->post('/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);
Needed to use the request method:
$batch[$key] = $fb->request('POST', '/'.$band_page_id.'/feed', ['message' => $band_name.' is playing today at '.$venue_name.' '.date('(l), g:ia', strtotime($event_start_datetime)), 'published'=>false, 'scheduled_publish_time'=>$sched_time], $pageToken);

PHP Twig Error: Object of class __TwigTemplate_XYZ could not be converted to string

Hey and good morning :).
I'll start with the error message and explain afterwards what I've tried and did:
Catchable fatal error: Object of class __TwigTemplate_[64chars] could not be converted to string in /someFolder/lib/Twig/Loader/Filesystem.php on line 139
The full error message as Image:
The PHP Error Message
The call stack as Text:
Call Stack
# Time Memory Function Location
1 0.0001 123400 {main}( ) ../handleOOP.php:0
2 0.0107 1269656 OOPHandler::runPage( ) ../handleOOP.php:7
3 0.0107 1269768 AnweisungEingeben->stepkontrolle( ) ../OOPHandler.php:62
4 0.0108 1271536 AnweisungEingeben->ausgabe( ) ../AnweisungEingeben.php:77
5 0.0383 1669484 Twig_Environment->render( ) ../AnweisungEingeben.php:442
6 0.0383 1669484 Twig_Environment->loadTemplate( ) ../Environment.php:347
7 0.0383 1669512 Twig_Environment->getTemplateClass( ) ../Environment.php:378
8 0.0384 1669512 Twig_Loader_Filesystem->getCacheKey( ) ../Environment.php:312
In the AnweisungEingeben.php I have the following code fragment:
include_once "../lib/Twig/Autoloader.php";
Twig_Autoloader::register();
$template_dirs = array(
$root.'templates/web/anweisungen',
[...]
);
$twig_loader = new Twig_Loader_Filesystem($template_dirs);
$twig = new Twig_Environment($twig_loader, array("debug" => true));
$template = $twig->loadTemplate('Anweisung_Base.phtml');
$wech = $twig->render($template); // line 442 from AnweisungEingeben.php
I already tried:
If the paths are correct (via scandir("path"))
If Twig gets loaded
Minimal Code like
$loader = new Twig_Loader_Array(array('index.html' => 'Hello World!'));
$twig = new Twig_Environment($loader);
echo $twig->render('index.html');
Unfortunately everything results in the same.
The strange thing is, that the exact same code is working flawlessly in a minimal project.
I know it's very chaotic, but the project is existing and growing now for about ~20 years and this twig approach is my try to start(!) separating the logic from the html code.
You're mixing methods up, you are trying to pass a Twig_Template to the Twig_Environment's render method, while this method actually expect the path to the template as it's first parameter
So either do :
$template = $twig->loadTemplate('Anweisung_Base.phtml');
echo $template->render();
Or
echo $twig->render('Anweisung_Base.phtml');

Laravel 4 Queued Mailing throws error while directly sending works

I have a Laravel 4 app where I need to send certain emails to users. I have no idea why but I keep getting this error on my test server (it does not happen on my local vagrant box)
Argument 1 passed to Illuminate\Mail\Mailer::getQueuedCallable() must
be of the type array, null given, called in
blablabla/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php
on line 238 and defined
I tried resetting everything: database, clean clone from git. None of these worked. I also cleared my browser cache and cookies out of desperation. I am using Sync queue. So it's not even an actual queue.
Mail::send works just fine. Mail::queue throws the error above.
I literally started to pull my hair out so any help will be greatly appreciated.
Here is my code:
This is my BookingMailer class that extends Mailer class.
// partner bir arabanın rezervasyonuna onay verdiğinde müşteriye gönderilecek ödeme linki
public function sendPaymentLinkToCustomer($customer, $partner, $booking) {
$view = 'emails.bookings.request_confirmed';
$data = [
'user' => $customer->full_name // string,
'partner' => $partner->display_name // string,
'reference' => $booking->reference // integer,
'booking_id' => $booking->id // integer
];
return $this->sendTo($customer, 'Booking Request Confirmed', $view, $data, true, true);
}
And this is my Mailer class that actually queues the mail.
public function sendTo($user, $subject, $view, $data = array(), $admin_copy=false, $send_as_pm=false)
{
Mail::queue($view, $data, function ($message) use ($user, $view, $data, $subject, $admin_copy) {
$message = $message->to($user->email)->replyTo(Config::get('mail.from.address'), Config::get('mail.from.name'))->subject($subject);
return $message;
});
}
Here is the solution to this problem (at least in my case)
I was including the user first and last name to the mail. I was only showing the first letter of the last name, though. And I was using substr for a UTF-8 string, and that's why sometimes it returned problematic characters that get inside the data array and ultimately cause the queue to break.
When i used mb_substr instead of substr, my problem disappeared.
Phew, I thought I would never figure this one out on my own.

Cannot declare phptemplate_settings() - Drupal error when trying to configure template

There are two templates, whitejazz and a modified whitejazz (forumwhitejazz) - both are enabled.
I'm trying to configure the modified whitejazz, and I am getting this error - what does it mean?
Should I post anything else to help deduce this? I'm utterly stumped - my googling of this issue has not given me any solid leads.
This is in Drupal 6.25
Fatal error: Cannot redeclare phptemplate_settings() (previously declared in /home/domain/public_html/drupal-6.25/sites/all/themes/whitejazz/theme-settings.php:3) in /home/domain/public_html/drupal-6.25/sites/all/themes/forumwhitejazz/theme-settings.php on line 135
The problem is that function phptemplate_settings() was defined twice. This goes to fatal php error.
What I suggest to do is:
Create file theme-setting.php in root folder of forumwhitejazz template
There define function as in example and put there code settings.
Example:
function forumwhitejazz_settings($saved_settings) {
$form = array();
$form['forumwhitejazz_example'] = array(
'#type' => 'checkbox',
'#title' => t('Use this sample setting'),
'#default_value' => $saved_settings['forumwhitejazz_example'],
'#description' => t("This option doesn't do anything; it's just an example."),
);
return $form;
}

Categories