# CronJob Error campaigns and segments

**URL:** https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234
**Category:** Product Support
**Created:** [May 31, 2024, 4:17pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234 "2024-05-31T16:17:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![domjag](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/domjag/32/12597_2.png) [@domjag](https://forum.mautic.org/u/domjag)
#### Post date: [May 31, 2024, 4:17pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234/1 "2024-05-31T16:17:11Z")

</div>

**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

---

<div class="post-metadata">

### Author: ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)
#### Post date: [June 1, 2024, 2:44pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234/2 "2024-06-01T14:44:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![domjag](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/domjag/32/12597_2.png) [@domjag](https://forum.mautic.org/u/domjag)
#### Post date: [June 1, 2024, 4:18pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234/3 "2024-06-01T16:18:30Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)
#### Post date: [June 2, 2024, 2:27pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234/4 "2024-06-02T14:27:01Z")

</div>

> [@domjag](#):
>
> I changed the cron job back to root user and it seems to have fixed the issue.

Which confirms that this was a permission issue.

> [@domjag](#):
>
> Not crazy about using root in this case.

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 😉

---

<div class="post-metadata">

### Author: ![domjag](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/domjag/32/12597_2.png) [@domjag](https://forum.mautic.org/u/domjag)
#### Post date: [June 2, 2024, 2:41pm UTC](https://forum.mautic.org/t/cronjob-error-campaigns-and-segments/32234/5 "2024-06-02T14:41:02Z")

</div>

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