CronJob Error campaigns and segments

Your software
My Mautic version is: 5
My PHP version is: 8.1
My Database type and version is: Mariadb 10x

Your problem
My problem is:
I can run Cronjobs manually however when they run in the scheduler I get the following error in my logs.

These errors are showing in the log:
console.CRITICAL: Error thrown while running command “mautic:segments:update”. Message: “flock(): Argument #1 ($stream) must be of type resource, bool given” {“exception”:“[object] (TypeError(code: 0): flock(): Argument #1 ($stream) must be of type resource, bool given at /home/campaign.imatr.net/public_html/app/bundles/CoreBundle/Command/ModeratedCommand.php:161)”,“command”:“mautic:segments:update”,“message”:“flock(): Argument #1 ($stream) must be of type resource, bool given”}

Steps I have tried to fix the problem: restarting the cron

I’m pretty sure you’re having a file access permission problem.

cron probably uses another user. Because of that it can’t open something called a lock file.

If it could open it, it would get a PHP resource object. If there is a problem the bool type false is returned. This is what the error message tells you.

Check your file permissions and what users are used for cron, your PHP CLI, and webserver.

It doesnt show up anymore in the logs - seems to be fixed, I changed the cron job back to root user and it seems to have fixed the issue. Im going to play around with it a little more. Not crazy about using root in this case. Thanks for the suggestion!

Which confirms that this was a permission issue.

I’d urge you to reconsider, as you’re opening up your system to a variety of indirect attack vectors. But of course it’s your decision :wink:

Thanks Peter, yes I am going to figure out why my permissions only work for root