I've updated my crontab using crontab -e to run the Laravel task scheduler every minute. It wasn't working so I set it to add its output to a log file, like so:
* * * * * php /path/to/project/artisan schedule:run >> cron_output.log
Now the log contains the following message:
Parse error: parse error in /path/to/project/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233
This is the method it points to (I've commented next to line 233):
function cache()
{
$arguments = func_get_args();
if (empty($arguments)) {
return app('cache');
}
if (is_string($arguments[0])) {
return app('cache')->get($arguments[0], $arguments[1] ?? null); //line 233
}
if (! is_array($arguments[0])) {
throw new Exception(
'When setting a value in the cache, you must pass an array of key / value pairs.'
);
}
if (! isset($arguments[1])) {
throw new Exception(
'You must specify an expiration time when setting a value in the cache.'
);
}
return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
}
I don't understand this issue, as Laravel runs normally otherwise. PHP version is 7.2 (based on php -v and also phpinfo()) so that shouldn't be a problem. Is it possible that somehow the crontab is using an older version of PHP? If so how do I fix this? Any other ideas?
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Since PHP 7.4.1 there is pear error with the newest version even though they said its fixed.
Example:
if you try to install any package using the "pecl" a warning error returns with the message:
Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
The repositories have already been updated, but the problem persists
I had the same issue and creating the temporary pear cache directory solved it.
mkdir -p /tmp/pear/cache
I met the same issue.
Notice: Trying to access array offset on value of type bool in REST.php on line 181
PEAR Version: 1.10.1
PHP Version: 7.4.1
Zend Engine Version: 3.4.0
Running on: Darwin kairee-mbp 19.2.0 Darwin Kernel Version 19.2.0
function useLocalCache($url, $cacheid = null)
{
if (!is_array($cacheid)) {
$cacheid = $this->getCacheId($url);
}
$cachettl = $this->config->get('cache_ttl');
// If cache is newer than $cachettl seconds, we use the cache!
if (time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}
return false;
}
/**
* #param string $url
*
* #return bool|mixed
*/
function getCacheId($url)
{
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (!file_exists($cacheidfile)) {
return false;
}
$ret = unserialize(implode('', file($cacheidfile)));
return $ret;
}
You may notice that when the cached file not exists, getCacheId will return false. In line 181, the code if (time() - $cacheid['age'] < $cachettl) { is trying to access array offset on false.
I add a condition to this line to fix it:
// If cache is newer than $cachettl seconds, we use the cache!
- if (time() - $cacheid['age'] < $cachettl) {
+ if ($cacheid && time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}
I met with the same problem while trying to install xdebug using PECL. Something about that code block that you quoted is causing problems. I think that's a problem somehow related to MacOS Catalina, saw three people with that error and all were using newest MacOS.
As a workaround I commented the 'if' block that you quoted. That seems to get the job done, as I could install xdebug normally after doing that.
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'm trying to run my travel project on AWS server.what I do is copy what I have done on the local computer to AWS server and change the .evn file when I run the project it is saying this error in the log file. (I did try to change permission in the folder but didn't work that also)
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'syntax error, unexpected ':', expecting ';' or '{'' in C:\MTASL\vendor\spatie\laravel-permission\src\PermissionRegistrar.php:33
Stack trace:
How can i fix this error.
updated
this the line that it says I did try to change what it says but didn't work
public function registerPermissions(): bool
{
try {
$this->getPermissions()->map(function ($permission) {
$this->gate->define($permission->name, function ($user) use ($permission) {
return $user->hasPermissionTo($permission);
});
});
return true;
} catch (Exception $exception) {
if ($this->shouldLogException()) {
$this->logger->alert(
"Could not register permissions because {$exception->getMessage()}".PHP_EOL.
$exception->getTraceAsString()
);
}
return false;
}
}
This line:
public function registerPermissions(): bool
is PHP 7 syntax. Remove ": bool" to have it work on older PHPs.
But chances are that the whole module requires a newer version of PHP than the one you have. The real solution is upgrade your PHP.
Look in your code at the line in question. The error tells you what the problem is. My guess without having seen anything is that the line ends in a : instead of a ;
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 using Laravel 5.1 to create a console based application. During development I would like to display the exception trace when an error occurs. However, even if I use -v -vv or -vvv option in php artisan, I don't get an exception trace for my custom commands. I set APP_DEBUG=true in my .env, still no exception trace.
Output of php artisan some:unknowncommand is:
[InvalidArgumentException]
There are no commands defined in the "some" namespace.
Output of php artisan -v some:unknowncommand is:
[InvalidArgumentException]
There are no commands defined in the "some" namespace.
Exception trace:
() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:501
Symfony\Component\Console\Application->findNamespace() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:535
Symfony\Component\Console\Application->find() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:192
Symfony\Component\Console\Application->doRun() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:126
...
Now, I created a very simple console command called dp:test, with following handle function:
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
generate error here
}
Output of php artisan dp:test is:
[Symfony\Component\Debug\Exception\FatalErrorException]
syntax error, unexpected 'error' (T_STRING)
Output of php artisan -v dp:test is the same.
Output of php artisan -vvv dp:test is the same.
The log file DOES show the exception trace, so somehow it should be possible to display it in cli. I don't even see the filename and linenumer where the error occurs... How can I take care of this?
Thanks in advance!
EDIT:
Is digged a bit further. In case I use this in my Command:
public function handle()
{
throw new \Exception("test exception");
}
and I issue the command php artisan -v dp:test, the error trace IS printed. The trace is only not printed when the exception is thrown due to a PHP error. In Illuminate/Foundation/Bootstrap/HandleExceptions.php method bootstrap PHP errors are converted to Exceptions. When this occurs, an exception is thrown, but the -v is somehow ignored when printing. This is very inconvenient because it makes debugging CLI apps hard.
I think the solution can be found in vendor/symfony/console/Application.php, method renderException.
I'm going to dig further later, unless someone else can point the solution faster than me :-)
I found reason why -v is ignored:
in Illuminate/Foundation/Bootstrap/HandleExceptions.php, the renderForConsole method instantiates a ConsoleOutput object, with default settings, not taking into account the verbosity settings the user asked for:
protected function renderForConsole($e)
{
$this->getExceptionHandler()->renderForConsole(new ConsoleOutput, $e);
}
For this reason, whatever -v -vv or -vvv is set, the $output->getVerbosity() in vendor/symfony/console/Application.php is always lower than OutputInterface::VERBOSITY_VERBOSE, for that reason, the stack trace is not printed.
I probably start an issue on github for this, because I think it's much more convenient if errors are shown in CLI if user sets -v.
You can set the verbosity to whatever level you'd like by adding the following use statement:
use Symfony\Component\Console\Output\OutputInterface;
And then adding this to the top of your handle function:
$this->output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
See the documentation for symfony console here http://symfony.com/doc/current/console/verbosity.html
for more information.
If you look at Illuminate\Console\Command class you will see the definition of the function that writes the error string to the console:
/**
* Write a string as error output.
*
* #param string $string
* #return void
*/
public function error($string)
{
$this->output->writeln("<error>$string</error>");
}
Now that you see it only writes the error string, you can play just a little bit with it to achieve what you want. You can get the function call back trace and output as many lines and files backwards as you wish. Just create class that extends command, override the function and make all of your commands to inherit that command class:
/**
* Write a string as error output.
*
* #param string $string
* #return void
*/
public function error($string)
{
$this->output->writeln("<error>$string</error>");
$trace = debug_backtrace();
foreach ($trace as $t)
{
$this->output->writeln("Trace : " . $t['file'] . " on line " . $t['line'] . " function " . $t['function']);
}
}