crunzphp / crunz

A PHP-based job scheduler
MIT License
180 stars 16 forks source link

Is it possible to execute crunz within PHP? #55

Closed pixobit closed 1 year ago

pixobit commented 1 year ago

I'm trying to achieve something like what wordpress is doing, just running cronjobs cronless. I tried doing it with with exec, but they don't seem to be executing, and might be something wrong with my setup, not sure yet. I would like to know whats the state of crunz on this before i dig deeper.

PabloKowalczyk commented 1 year ago

Do you mean something like that: https://github.com/WyriHaximus/reactphp-cron?

pixobit commented 1 year ago

No. What I meant is way more simpler than that. Basically just gets executed when someone makes a page request.

The way i was trying to achieve it, is once the page is loaded, i send a request to a url which executes crunz with the help of the exec function, but it didnt seem to execute my tasks, so I was wondering if for some reason this won't work.

Eventually this should also make it possible to call the cron externally by calling that endpoint.

PabloKowalczyk commented 1 year ago

I see, do you even need Cron/Crunz for running tasks on request? You can force running task if run time doesn't matter.

Also make sure Crunz is really executed from request. check path, process exit code and stdout/stderr, maybe you missing something.

Crunz doesn't limit execution to any SAPI so doesn't look like Crunz issue.

pixobit commented 1 year ago

I see, do you even need Cron/Crunz for running tasks on request? You can force running task if run time doesn't matter.

Also make sure Crunz is really executed from request. check path, process exit code and stdout/stderr, maybe you missing something.

Crunz doesn't limit execution to any SAPI so doesn't look like Crunz issue.

Figured it out, and wanted to leave the details here just in case someone else runs into this issue as well.

The issue was originating from crunz not finding the crunz.yml config file, and not knowing the timezone throws an error. The reason it wasn't seeing the config file, was that getcwd used by crunz was returning a different directory from what was expected, since the webapp was started from the public directory... The solution was to use chdir() to set the rootpath before calling crunz with exec().