so I got this code:
public static function postAllTasks()
{
$allTasks = Tasks::getTasksForToday();
foreach ($allTasks as $task) {
$delay = DB::table('jobs')->count()*20;
PostTasks::dispatch((string)$task->task)->delay($delay);
}
}
It is working fine on my computer just fine, but as soon as it is on the server it returns the error:
Error: Call to undefined function App\Http\Controllers\Traits\curl_init() in /var/www/html/app/Http/Controllers/Traits/TaskTrait.php:89
Stack trace:
#0 /var/www/html/app/Http/Controllers/Traits/TaskTrait.php(224)...
The problem is, that the PHP curl extension is active and visible + when I run exactly the same PHP artisan command, which doesn't use the dispatch/worker but just execute the Job (so it is using curl anyway) right away, everything works.
When I use:
QUEUE_CONNECTION=sync
instead of
QUEUE_CONNECTION=database
It works too, but I need it to use the database in order to calculate the delay between each job.
Laravel Framework 8.55.0
PHP 7.4.3
Related
My job sometimes throws an exception:
Undefined index: job
#1 D:\home\site\repository\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(192): Illuminate\Queue\Jobs\Job->failed(Object(Exception))
#2 D:\home\site\repository\vendor\laravel\framework\src\Illuminate\Queue\InteractsWithQueue.php(47): Illuminate\Queue\Jobs\Job->fail(Object(Exception))
The corresponding function in the framework (Job.php):
protected function failed($e)
{
$payload = $this->payload();
[$class, $method] = JobName::parse($payload['job']);
...
So it seems that job is not set in payload. Where and how does it get set? I never do this manually and I think this should always be set automatically by laravel!?
I did not have this issue before I upgraded to laravel 8 from 5.8
I made loads of changes within my code and unfortunately kind of lost track what were the last one.. but I guess one of them created this weird problem.
When I'm trying to run php artisan serve, I get this error -
Parse error: parse error in /Users/Guest/admanager/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500
And the function that returns the error in helpers.php looks like this -
function factory()
{
$factory = app(EloquentFactory::class);
$arguments = func_get_args();
if (isset($arguments[1]) && is_string($arguments[1])) {
return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ? null); // specifically, this is line 500
} elseif (isset($arguments[1])) {
return $factory->of($arguments[0])->times($arguments[1]);
}
return $factory->of($arguments[0]);
}
Please change as per below code,
$arguments[2] ? null TO $arguments[2] ?? null
The problem was that I just uninstalled xampp and it downgraded my locally running php version, hence the artisan serve didn't know how to handle that.
I am attempting to generate a php-symfony server stub using swagger-codgen but I am not getting an index.php (or app.php or anything like that).
When I generate a server stub using the php-silex preset I get an index.php. If I google "silex .htaccess" I can easily find the mod_rewrite directives to get it working. However, when I generate code using the php-symfony preset I cannot find the entry point.
I attempted to combine the php-silex and php-symfony generated codebases (since silex is a symfony project) like so:
(index.php):
use Swagger\Server\Controller\GetTypesListController;
$app->GET('/image/list/types', function (Application $app, Request $request) {
$tlc = new GetTypesListController();
$response = $tlc->getTypeListAction($request);
return $response;
//new Response('How about implementing getTypeList as a GET method ?');
});
However, then I get errors like:
"Fatal error: Uncaught Error: Call to a member function getApiHandler() on null"
I modified the getApiHandler function of my generated GetTypesListController to instantiate the apiServer variable:
public function getApiHandler()
{
if (!isset($this->apiServer)){
$this->apiServer = new \Swagger\Server\Api\ApiServer();
}
return $this->apiServer->getApiHandler('getTypesList');
}
but this just gave me another error:
Undefined property: Swagger\Server\Controller\GetTypesListController::$container
(referencing SymfonyBundle-php/Controller/Controller.php on line 149)
I am obviously doing something wrong. I would really appreciate being pointed in the right direction.
Edit: I do realize that I'm not supposed to call controllers inside controllers.. I assume that I'm not supposed to combine these two generated codebases at all.
I am trying to get the output of the command scheduled:summary function of laravel 5 and echo it in the browser, what i am currently doing is the following
public function scheduledCommands()
{
$output = new BufferedOutput;
Artisan::call('scheduled:summary',array(),$output);
return $output->fetch();
}
When i call this function i get this following error :
Use of undefined constant STDOUT - assumed 'STDOUT'
This method works for any other command just fine but this one, also when i execute it from CLI everything works fine and i get a table like this with my scheduled commands:
I don't understand what is different with this command, any further on why i get this error will be appreciated.
I'm getting a weird error trying to use PHP Artisan. I don't know the cause, or even which file is causing it.
Just a few moments ago I ran php artisan migrate:reset to wipeout all the tables in my db. Worked fine.
Then I made a change to a file completely unrelated to the "stages" table, and when I try to run php artisan migrate it throws an error saying:
SQLSTATE[42S02]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'stages'. (SQL: select * from [stages] where [stages].[deleted_at] is null order by [opord] asc)
It throws that error no matter what I try to do, even just typing php artisan causes that fatal error.
Also, if I manually add a table called "stages" to the DB, artisan doesn't fail immediately, it tries to migrate the tables, then fails when it gets to the stages table, and it says it failed because "stages" already exists.
I don't even understand why artisan is trying to perform a select statement when I'm just trying to migrate my tables; and I especially don't understand why it's happening when running the php artisan command alone.
EDIT:
I traced the problem to some code that I had added to app\Providers\AppServiceProvider
public function boot(){
View::share('nav_stages', Stage::opord()->get());
}
I found a SO question about how to check if a table exists and I'm currently trying to make this work:
public function boot(){
if (Schema::hasTable('stages'))
{
View::share('nav_stages', Stage::opord()->get());
}else{
View::share('nav_stages', null);
}
}
The problem was caused by a bit of code I had in AppServiceProvider.php In the code I was trying to query the DB for data required by the navigation menu used on the entire site (a master page, layout, partial view, etc).
I replaced
public function boot(){
View::share('nav_stages', Stage::opord()->get());
}
With
public function boot(){
if (Schema::hasTable('stages'))
{
View::share('nav_stages', Stage::opord()->get());
}else{
View::share('nav_stages', null);
}
}
And added
use Illuminate\Support\Facades\Schema;
at the top of the file