Allowed memory size of 8589934592 bytes exhausted
इस तरह की त्रुटियां मेमोरी में बड़ी मात्रा में डेटा के कारण होती हैं, इसलिए इसे ठीक करने का तरीका कम भारी मेमोरी स्क्रिप्ट लिखना है। memory_limit
changing को बदलकर हमें केवल अस्थायी रूप से ठीक किया जाता है क्योंकि जब हमारा डेटा बढ़ता है तो वह वापस आ जाता है।
$campaigns = Campaign::all(); //at this point you are pulling the whole Campaigns table to memory.. and you pull some extra rows after that increasing even more the memory use
जैसा कि मैंने कहा, एलोक्वेंट इस तरह के कार्य को करने में खराब कुशल है तो चलिए डेटाबेस पंक्तियों को एक-एक करके लाते हैं जैसा कि mysqli करता था:
$db = DB::connection()->getPdo(); //get a database connection instance
$main_query_sql = "SELECT * FROM Campaigns"; //write our query
$main_query = $db->prepare($main_query_sql); //prepare it to get executed
$main_query->execute(); //execute our query
$visits_denied_sql = "SELECT COUNT(*) as total FROM VISITS WHERE DENIED = 1 AND CAMPAIGN_ID ="; //let's prepare our aggregate queries
$visits_allowed_sql = "SELECT COUNT(*) as total FROM VISITS WHERE DENIED = 0 AND CAMPAIGN_ID ="; //I just assumed them so change it as you need
$visits_denied = null;
$visits_allowed = null;
while($campaign = $main_query->fetch()){ //fetch our rows one by one
//now we are getting an associative array from the db instead of a model so we cannot use it as a Laravel Model (we can't use ->save() method or eager loading)
$visits_denied = $db->prepare($visits_denied_sql.$campaign['id']);
$visits_denied = $visits_denied->execute();
$denied_visits = $visits_denied->fetch();
$visits_allowed= $db->prepare($visits_allowed_sql.$campaign['id']);
$visits_allowed= $visits_allowed->execute();
$allowed_visits = $visits_allowed->fetch();
$campaign['denied_visits'] = $denied_visits['total'];
$campaign['allowed_visits'] = $allowed_visits['total'] ;
//edit with the correct update sentence:
$insert_query_sql = "UPDATE CAMPAIGNS SET allowed_visits = :visits_allowed, denied_visits = :visits_denied WHERE id = :id";
$insert_query = $db->prepare($insert_query_sql);
$insert_query->bindParam(':visits_allowed', $campaign['allowed_visits']);
$insert_query->bindParam(':visits_denied', $campaign['denied_visits']);
$insert_query->bindParam(':id', $campaign['id']);
$insert_query->execute();
}
इसे अपने शेड्यूल के अंदर आज़माएं और मुझे बताएं कि क्या काम किया है!