Any way to delete a php script task file after its execution
First, thanks for this awesome library. I am using it for learning purposes. I have a few tasks in my tasks directory, all of which are php files running with the PHP BINARY by Crunz. I was wondering if there is a way to delete the php file after its execution.
Things that I have tried to achieve this:-
- Tried adding
UNLINK(__FILE__);to the task php. But, I can't have it beforereturn $scheduleas the script won't complete and the task file gets deleted. I can't have it afterwards either, as anything afterreturn $scheduledoesn't run. - I also tried running the scheduler to delete the file
$schedule->run(PHP_BINARY . -r 'UNLINK(__FILE__');But,__FILE__here returns a value ofCommand line codeand I tried various versions of it, but none of them work.
I am trying to self destroy the task once it has been executed from within the task php file itself. I am aware of using sh or bash to do this. But, I would really love to know if there was a way to achieve this from within the PHP file itself.
I think you could try to call unlink in Closure passed to \Crunz\Event::after.
I think you could try to call
unlinkin Closure passed to\Crunz\Event::after.
Thanks for this. But, upon rechecking, I had totally forgotten about the pre and post-hooks functionality. I will also have to try if after on schedule would work. WiIll report back.