I am trying to schedule a task in windows task scheduler what i want is have to run a url every 5 minutes without opening browser i tried using
php -f http://localhost/sms/test.php
wget -q -O - http://localhost/sms/test.php > tmp.txt
and also the full path
php -f C:/Bitnami/redmine-2.4.3-0/apache2/htdocs/sms/test.php
it shows the same error
Task Scheduler failed to start instance
"{a889332e-87f0-421b-accc-4ff19ae98599}" of "\test" task for user
"PUGOSTECH\xxxxx" . Additional Data: Error Value: 2147942402.
I understand that i am making a silly mistake to create scheduler but dont know how to find?
If i use by opening browser command it works fine like
cmd /c start http://localhost/sms/test.php
Related
I'm using Heroku to host a Lumen app. I've setup the logging to send messages to stdout:
// bootstrap/app.php
$app->configureMonologUsing(function ($monolog) {
/** #var Monolog\Logger $monolog */
$monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
});
I've tested this works by adding a log message to the schedule function
protected function schedule(Schedule $schedule)
{
\Log::info('Running cronjobs.');
$schedule
->command('update:daily')
->timezone('America/Los_Angeles')
->everyMinute();
}
The Heroku logs show:
Jan 19 09:42:15 service app/scheduler.4140: [2018-01-19 17:42:14] lumen.INFO: Running cronjobs. [] []
Jan 19 09:42:15 service app/scheduler.4140: Running scheduled command: '/app/.heroku/php/bin/php' artisan update:daily > '/dev/null' 2>&1
However the update:daily command has a number of log messages inside it and none of them are showing up.
I thought this might be because of the > '/dev/null' so I tried adding ->sendOutputTo('php://stdout') and ->sendOutputTo(base_path('storage/logs/cronjobs.log')) to the scheduled task but neither works.
Here's my Procfile:
web: vendor/bin/heroku-php-nginx -C heroku-nginx.conf -l storage/logs/cronjobs.log public/
Ethan is right with his observation regarding > '/dev/null'. As Heroku collects logs from stdout and stderr - scheduled tasks are not being logged correctly.
Luckily there's a simple workaround: log to a file, and output it's content into stdout. Heroku will then be able to log everything, whether using its native logging or using an add-on like LogDNA, Papertrail, etc.
Given that you're logging to a single channel in logging.php, into the file storage/logs/laravel.log, replace your scheduler command php artisan schedule:run with the following:
touch ./storage/logs/laravel.log; tail -f ./storage/logs/laravel.log & php artisan schedule:run
What it does?
Makes sure a log file exists. If it didn't - the following command will fail
Tails the log file, so its content is outputted to stdout
Starting the Laravel scheduler
The advantage of using this method is that you don't need to change your code, rather the configuration and the environment, so if you're running the app on other platforms - it won't change the way they work/log.
Laravel uses the > '/dev/null' when you do not call ->sendOutputTo(). I couldn't figure out an appropriate way to use the ->sendOutputTo() function to send to stdout.
What I did to fix this issue was change the ->command() function to a ->call(function(){}) function and executed the same single line of code the terminal command could have called. When laravel calls a Closure, it does not dump the output to > '/dev/null'.
Im running this code in my php file:
shell_exec('echo wget http://192.168.20.1:8080/proj/add_user/ | at -t 201606281053');
in my var/log/httpd/error_log, it says "PAM failure System error".
I'm trying to add a scheduled task in my server but this doesn't seem to work.
I refer to this thread but no success.
how to pass arguments to linux at command
Thank You!
I have MATLAB r2013b, IIS 7.5, php 5.6 on Windows Server 2008 and trying to do the following:
<?php
...
chdir($matlabScriptsDir);
exec("matlab -r test_func(args) -logfile $logfile", $output);
$output shows that process exited with code 0, in the TaskManager I see MATLAB.exe running from the user IUSR, $logfile is created and locked by this process, but the process does nothing – just hangs (there are no issues with running the same command from cmd.exe).
Where is the problem?
using the -r option is like entering commands to Matlab's command line, so after the command is executed you still have Matlab running, waiting for your next command. Try instead:
matlab -r "test_func(args), exit"
So that the Matlab process will end. I suggest you do even more, and wrap it with a try-catch (followed by exit) so that in case of an error the process will not hang.
I try to plan one-time job with 'at' command. There is next code in script:
$cmd = 'echo "/usr/bin/php '.$script_dir.$script_name.' '.$args.'"|/usr/bin/at "'.$time.'" 2>&1';
exec($cmd, $output , $exit_code);
When I run this command from script it adds the job to the schelude. This I see by the line in logs job 103 at Thu Sep 3 15:08:00 2015 (same text contains $output). But then nothing happens in specified time like at ignores the job. And there are no error messages in logs.
When I run same command with same args from command line on server it scheludes the job and than runs it at specified time.
I found out that when I try to plan a job via php script it runs under apache user. I tried to run next in command line on server:
sudo -u apache echo "/usr/bin/php /var/www/pant/data/www/pant.com/scripts/Run.php firstarg secondarg "|/usr/bin/at "16:00 03.09.2015"
It works correct too. I checked sudoers and have added apache user with NOPASSWD privileges. Script Run.php has execute rights.
at.deny is empty. at.allow does not exist.
So question is: why 'at' does not run command given via php script (exec) but runs same command in command line? How to run it?
Thanks to all.
I found by chance answer at stackexchange.com:
The "problem" is typically PHP is intended to run as module in a webserver. You may need to install the commandline version of php before you can run php scripts from the commandline
folks,
i am very new to PHP, on project that i do now(PHP + Linux), i need to schedule tasks. I know that i can do it using cron. How can i check crontab file from PHP(i have only ftp access to server)?
I mean i can run 'crontab -l' from terminal(on my local PC). But when i try to do :
echo exec('crontab -l'); - on local PC, it retrn nothing, why it happend ? How can i run command 'crontab -l' from PHP and get output ?
I've tried to use example http://ryanfaerman.com/read/php-crontab-manager, but get compile error.
I think crontab will open the user's crontab. Your webserver might be running as root or a different user than you would be.
Try this, but I doubt it will work for security reasons:
crontab -u root -l
I got nothing from exec('crontab -l'), because i haven't permissions to run crontab and error message is in error stream, so all i need redirect error stream to out stream.
exec('crontab -l 2>&1') - that is exactly i wanted.