-3

我需要实现一个每天早上 8:00 运行的 cron 作业。我不知道需要做什么。cron 应该在这个文件上运行一个函数 greet()。

<?php
    class Person {
     public $age=0;
     public  $isalive=false;
     public $name;
     public $msg;
     public $isAlive=true;
     public $firstname;
     public $lastname;

     public function __construct($fname,$lname,$age){
        $this->firstname=$fname;
        $this->lastname=$lname;
        $this->age=$age;
        $this->name=$fname." ".$lname;
        //$this->isAlive=$isAlive;
     }

         public function greet(){
             echo "$this->name says $this->msg my age is $this->age <br> am I alive:$this->isAlive";
         }
    }
     $teacher = new Person('boring','12345',12345);
     $student = new Person('Swapnil','Shende',24);
     echo $student->age;

     ?>
4

2 回答 2

1

转到cron选项卡并像这样打开它

crontab -e

然后添加这一行

* 8 * * *   filename.php

其中 filename.php 是您的文件名

还要编辑你的 file.php 以在最后调用这些函数

 $teacher = new Person('boring','12345',12345);
 $student = new Person('Swapnil','Shende',24);
 $student->greet();
 $teacher->greet();
于 2013-05-15T13:06:18.137 回答
0
crontab -e
* 8 * * *  file.php

其中 file.php 包含:

<?php
include ('Person.class.php');
$teacher = new Person('boring','12345',12345);
$student = new Person('Swapnil','Shende',24);
$teacher->greet();
$student->greet();
?>

并从你的班级中删除这部分

$teacher = new Person('boring','12345',12345);
$student = new Person('Swapnil','Shende',24);
echo $student->age;
于 2013-05-15T13:12:50.690 回答