What's new

Run php script from the command line

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Yah

Occasional Visitor
Hi All,
I would like to run a php script from the command line or as a scheduled task. The script downloads and unrar files in a folder. I installed php-cli. Running "php script.php" from the command line didn't work. I changed to "php-cli script.php" and it worked, but after script launched R700 memory used by the script didn't get released. I had about 80MB used before and 210MB after. Any suggestion how that can be improved?
Thanks
 
I added a command to cleanup cache after execution and that looks brings memory to normal state
Code:
#!/bin/sh
php-cli /opt/usr/scripts/update.php
sync; echo 1 > /proc/sys/vm/drop_caches
 
Normal state is what you had before....the memory will be freed/used when another process requires it. If you read the Linux docs, drop_caches should only be used for testing purposes.
 
Thanks for your comment. If I have just about 20M free memory after script execution, do you suggest to enable swap file. It'll be on a USB flash, not sure how fast it is in writing.
 
Personally, I wouldn't recommend creating a swap file unless you are experiencing "out of memory" errors. Basically, don't try to fix a problem that doesn't exist.
 
Thanks for your comment. If I have just about 20M free memory after script execution, do you suggest to enable swap file. It'll be on a USB flash, not sure how fast it is in writing.

I tend to agree with ColinTaylor. Given your description of the app, I doubt it would actually use/need a swap file. The only time I've seen feedback that a swap file was actually used was for people running a torrent application on the router and really beating on it with multiple torrents.

That being said, if you would like to experiment, it's not hard to set up a swap file. I'd put it on a USB3 stick for the fastest possible performance. I set one up (mostly for testing) and try as I might, I've never seen it being used. Linux memory management is actually pretty good.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top