Comments (4)
So I forked this and played around a bit. I found it not working on Windows because of the (' . $compiled . ') > /dev/null 2>&1 &
section of Run::compile(). This isn't valid for someone running WAMP. I added a check for the OS to resolve that.
if ($this->canRunInBackground()) {
// Parentheses are need execute the chain of commands in a subshell
// that can then run in background
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$compiled = '(' . $compiled . ') > /dev/null 2>&1 &';
}
else {
$compiled .= ' > NUL';
}
}
I also added some options to the config of scheduler to define a working folder to execute from that would supplant the bin if defined.
Let me know if you are interested in the fork code.
from php-cron-scheduler.
@SageDavis is the problem the path to the php bin? If so, you can set it as a second parameter so no need to worry where the script to execute is located. I would also suggest (in your case) to use absolute paths when scheduling your scripts, for example
$scheduler->php(
'/absolute/path/to/my/script.php', // The script to execute
'/absolute/path/to/my/custom/bin/php' // The PHP bin
);
But maybe I am not following your scenario, if so please provide an example.
About the second comment, to be honest in the beginning I didn't put any effort to make it works for Windows, thinking that if used in conjunction with the crontab that would only have been available on unix systems.
I am not familiar enough with Windows to know for sure if that code works, but I trust you saying that works. Although I have a question, would the script run in background or in foreground when doing
$compiled .= ' > NUL';
and if not, is there a way or running it in background? Otherwise the OS check might make more sense to be added on the if above
if ($this->canRunInBackground() && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
...
}
I'd like to see your changes yes, if you can please add a link
from php-cron-scheduler.
@SageDavis Thanks for your code ! I've also been trying to make it work on Windows (have it on my local machine) and your trick definitely made the job.
from php-cron-scheduler.
@SageDavis is the problem the path to the php bin? If so, you can set it as a second parameter so no need to worry where the script to execute is located. I would also suggest (in your case) to use absolute paths when scheduling your scripts, for example
$scheduler->php( '/absolute/path/to/my/script.php', // The script to execute '/absolute/path/to/my/custom/bin/php' // The PHP bin );
But maybe I am not following your scenario, if so please provide an example.
About the second comment, to be honest in the beginning I didn't put any effort to make it works for Windows, thinking that if used in conjunction with the crontab that would only have been available on unix systems.
I am not familiar enough with Windows to know for sure if that code works, but I trust you saying that works. Although I have a question, would the script run in background or in foreground when doing
$compiled .= ' > NUL';
and if not, is there a way or running it in background? Otherwise the OS check might make more sense to be added on the if above
if ($this->canRunInBackground() && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { ... }
I'd like to see your changes yes, if you can please add a link
This works in the background on Windows. the challenge is that it's a console command and commands are different between OSs, as does relative references. If you are working with a php based website calling some scripts on the server itself you have to call it from the root or relative references will not work. The first comment was in relation to calling the script in a way that would still work for relative placed libraries. The second comment with the code addresses the console syntax for opening something in the background
php-cron-scheduler.zip
I did the changes local, but have attached here.
from php-cron-scheduler.
Related Issues (20)
- CRON JOB not running automatically but run manually HOT 3
- Support PHP8.0
- how to get the number of running tasks?
- daily() and php() not working
- How does the lock file removed HOT 2
- Intelephense suggestion issue
- Minute Error HOT 1
- Task start and end time
- cannot output log file HOT 1
- no way to set timezone for each job
- This library does not work for windows HOT 3
- work() cpu 100% HOT 2
- PHP 8.1 compatibility HOT 1
- Upgrade for php version 8.1 HOT 1
- Passing date will not execute the code in background
- Error when Scheduling an Object Method using ->call()
- Remove lock file of failed only-one callable job HOT 3
- Passing parameters via register_argc_argv alternative
- How to start a worker timer function upon startup?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-cron-scheduler.