Giter VIP home page Giter VIP logo

Comments (4)

 avatar commented on June 12, 2024

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.

peppeocchi avatar peppeocchi commented on June 12, 2024

@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.

quentinboinet avatar quentinboinet commented on June 12, 2024

@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.

 avatar commented on June 12, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.