Executing a PHP script every few seconds

Open /etc/crontab with VI and add lines similar to the ones seen below. Make sure to use <tab> instead of spaces!

* * * * * root php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 10; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 20; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 30; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 40; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 50; php /your/file/location.php > /dev/null 2>&1

 

Restart cron deamon using the command show in this post.

Job control on synology via SSH

This command will keep your process running in background even when closing the SSH connection to your synology.

 

nohup your_command >out.log 2>&1 </dev/null &

Enabling extensions in PHP CLI on a synology DS

This guide shows how to enable extensions in PHP CLI (command line interface).

Check your php ini location

php --ini

Change to the folder to where the php.ini is located given by the previous command which was in my case

/usr/local/etc/php70/php.ini

Use vi to edit the file

sudo vi php.ini

Change the extension dir path in php.ini to /volume1/@appstore/PHP7.0/usr/local/lib/php70/modules. Depending on your PHP version the location might differ.

Enable the extension by adding the following code line to your php.ini. Here’s an example showing how to enable PDO_mysql support.

extension = pdo_mysql.so

I had to the correct php executable. In my case it was located under

/volume1/@appstore/PHP7.0/usr/local/bin

There is no restart of any kind necessary to make this work as php.ini is initialised on every start when using PHP CLI. If you want to enable the extension on your webserver you have to to use the DSM settings for webstation to do it.

Back to Top