5

I've got some problems with the scheduled task feature in Plesk while setting up a task that should execute a php-file every minute. screenshot

As you can see in the screenshot, everything should be fine and executing the task seems successfully completed. The php-script contains one line of code:

file_put_contents('./test.txt', date("d.m.Y H:i:s"), FILE_APPEND);

So it writes the current date and time to the file, cool. If i open that file directly in my browser (http://example.com/test.php) it works (test.txt is writeable with 777)

But it doesn't work automatically (every minute) and also fails when trying to hit the "Execute now"-button in Plesk (see screenshot, bottom left button). Obviously I see a success-message, but nothing happened (test.txt does not contain new content and time of last modification does not change).

  • Ensure emails send every time script runs - not just on errors. Ensure error handling/debug on script is output - you will get that then in an email. Might help you drill down to problem. – user29671 Mar 16 '16 at 15:08
  • @user29671 i set display_errors an error_reporting to output all errors but nothing happens. I also sent an email in my php-script, this works too. But it wont write content to the test.txt... – user61972 Mar 16 '16 at 15:39
  • I would be ensuring the script works in the most basic form by cron - eg example one here > php.net/manual/en/function.file-put-contents.php – user29671 Mar 16 '16 at 15:43
  • 1
    Does it ever write to that file? Files in the document root should not be writeable (the directory itself also needs to be writeable) as this is a security risk. Also, in the context of the command line, what does ./ refer to? – DocRoot Mar 16 '16 at 16:18
  • It's great that you solved this, however the title shouldn't be edited to reflect that. It would be better instead if you or @user29671 answered this below so it's clearer to others, and then you can accept that. – dan Mar 17 '16 at 7:13
1

I replicated the issue on a PLESK 12 node and solved it.

file_put_contents('**./test.txt**', date("d.m.Y H:i:s"), FILE_APPEND);

Apply the full path to the PHP file for the output script:

The PHP file:

<?php
file_put_contents('/var/www/vhosts/domain.tld/webroot/test.txt', date(" 'd.m.Y H:i:s' "), FILE_APPEND);
?>

Output after 3 Crons:

'07.04.2016 02:41:32'  '07.04.2016 02:41:40'  '07.04.2016 02:42:01' 

With the ./test.txt path it was only able to write one time - with the full path its writing every cron.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy