1
emyu10
6y

Does, running a php script every 5 seconds as a background process, takes up the whole memory allocated for the process that runs php-fpm and stop serving to apache?

(I don't really know what I am talking about)

Comments
  • 1
    As long as your script doesn't hang, it'll exit and release what little memory was allocated to it. So php-fpm may be allowed 2G but if your script only uses 14M it'll only use that much and then release it.

    But I could be talking out of my arse. 🤷‍♀️
  • 0
    Let me explain the scenario.

    I have 2 php scripts, a.php and b.php

    a.php has an infinite while loop. Each iteration runs b.php and then sleeps for 5 seconds.

    Then I run a.php on the terminal appending & in order to send it to the background.

    So the while loop in a.php keeps running in the background and after sometime, the web server starts sending 503.
  • 1
    @emyu10 Oh okay. I'm just guessing this here but I would say that every time a.php spawns b.php, it allocates memory but won't release it until the while loop is exited. So it builds until you run out.

    Is b.php not something you can cron?
  • 0
    @scytheri0n I don't know how to cron.
  • 1
    @scytheri0n this.
    Cron it. Also on an unrelated note, why PHP?
  • 1
    @emyu10 Time to learn ;) But essentially your cron entry would look something like:

    */5 * * * * /usr/bin/php /path/to/b.php

    You have to put the full path to your php executable because $PATH doesn't exist for cron jobs.

    If in doubt: man crontab (:
  • 1
    @scytheri0n yes obviously. It's right under my fingertips, yet I don't learn it.

    @JKyll php because I don't manage the server. Not authorized to install anything. Plus I am only confident in php. Thought of using python for the job. But it's not installed.

    BTW: b.php checks an online server for updates and 'act upon it'.

    The server we are working on can't be accessed from outside.
  • 0
    @emyu10 why would you need to check for updates every 5 seconds? try increasing the 5 seconds to 5mins or 5 hours even.
  • 0
    @helloworld in this particular case, it needs to be close to real-time
  • 1
    Just realized the cron line I gave you is for minutes. Because it's the end of the day and I don't ready properly.
  • 0
    Or taip
  • 1
    @scytheri0n it's ok. I don't just copy and paste without understanding first.
Add Comment