How can I solve the problem of insufficient server memory during scheduled tasks?

Source: Internet
Author: User
{Code ...}
  ignore_user_abort(true); set_time_limit(0);  $b = str_repeat(' ', 10000);  $i = 0;  ob_start(); while (true) {     sleep(1);     file_put_contents('sf.txt', date('Y-m-d H:i:s') . $i . "\r\n", FILE_APPEND);      echo $i,$b,'
'; ob_flush(); flush(); }
I did not expect a few seconds of Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133437441 bytes) in/data/home/hyu1658240001/htdocs/. php on line 16 is like this ah I just want to do a scheduled task, constantly detect timeout payment orders, to achieve automatic closure of timeout orders, why not ??? I have canceled the time limit. Is there a configuration with unlimited memory?

Reply content:
  ignore_user_abort(true); set_time_limit(0);  $b = str_repeat(' ', 10000);  $i = 0;  ob_start(); while (true) {     sleep(1);     file_put_contents('sf.txt', date('Y-m-d H:i:s') . $i . "\r\n", FILE_APPEND);      echo $i,$b,'
'; ob_flush(); flush(); }
I did not expect a few seconds of Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133437441 bytes) in/data/home/hyu1658240001/htdocs/. php on line 16 is like this ah I just want to do a scheduled task, constantly detect timeout payment orders, to achieve automatic closure of timeout orders, why not ??? I have canceled the time limit. Is there a configuration with unlimited memory?

Are you sure there is a problem with the script?

Run the script separately. OK?

Check whether the script is correct.

If an error is reported, the memory is not enough. it may be a logical problem.

This is an endless loop to change other solutions.

The file_put_contents function keeps occupying the memory.

Execute php scripts with linux scheduled tasks

Usesleep(2), Takes a few seconds to rest the program

I use oracle job stored procedures, but the frequency is low. or the condition is triggered when the order is used. after all, it is only necessary to consider whether it is valid when used.

Run with nodejs

I understand that your purpose is:Automatically closes unpaid orders that have timed out

You can try another solution:
Change the scheduled task to: clickOrder pageCheck whether there are unpaid orders due to time-out. If yes, disable them.

Crontab

Split into task queue for execution

1. you need to change the program to run in php-cli mode, that is, try the php command for execution. For example:/usr/local/php/bin/php index. php
2. change the while loop in the script and use crontab to execute the script. after the php script is executed, the running memory of the entire php script will be recycled and no memory overflow will occur.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.