我有一個功能,在嚴格針對OOP原則的同一時間執行大約5個任務。任何人都可以幫我破曉嗎?特別是在其他函數中調用函數對我來說是一種棘手的問題。PHP:使用單個任務打破函數功能?
public function status(){
$client = new Client();
$notification=Notification::where('active',1)->get();
$status = Status::where('name', 'health')->first();
$default_frequency = 1;
foreach ($notification as $note) {
$status_health = $note->status('health');
$check_frequency = isset($note->check_frequency) ? intval($note->check_frequency) : $default_frequency;
$date = \Carbon\Carbon::parse($status_health['timestamp']);
$elapsed_time = $date->diffInMinutes();
if($elapsed_time < $check_frequency){
continue;
}
$response = $client->get($note->website_url, ['http_errors' => false]);
$resCode = $response->getStatusCode();
$note->statuses()->attach($status,['values'=> $resCode === 200 ? 'up' : 'down']);
}
}
那麼你逐項5任務你想成爲獨立的方法,有人可能會幫助你 – RiggsFolly
是的。因爲這個類很重要,我會反覆調用不同類的函數。這就是爲什麼我現在要破曉的原因。 –
是的,我知道,但**給我們這個代碼中的5個任務的列表,你相信你想分成5個新的方法**我沒有看到5個單獨的任務,所以我顯然是愚蠢的,需要你的幫助 – RiggsFolly