Cron tasks
-
@girish Yes, the task was on the list.
The plugin people ask me what is the code with which Cloudron starts wp-cron to see if it is compatible.
EDIT: I have seen the error. Screenshot: https://prnt.sc/26qc3mk
-
@girish Side note but FWIW, it may be worth updating/clarifying the documentation here: https://docs.cloudron.io/apps/wordpress-developer/#cron-tasks
The doc saying "
The app is configured to run WordPress cron tasks every minute.
" seems a bit conflicted with the statement later that reads "WordPress' built-in cron task schedule wp-cron is disabled since it is not effective for low traffic websites.
"I believe we're running our own cron tasks in Cloudron which manually invokes the WP-Cron every minute instead of the default behaviour of WP running it itself only when the website is visited, correct?
-
@d19dotca Right...
wp-cron
with the hyphen refers to the filewp-cron.php
which is this PHP code that runs WP cron jobs via apache. Of course, PHP code only runs if someone visits the web site. So, if no one visits your site for an hour, cron jobs are not run. So, on Cloudron (and most other WP hosts), we set up an external scheduler/timer to run the cron jobs.I guess what is being said is
The app is configured to run WordPress' cron tasks every minute without using the built-in wp-cron
-
@girish have you seen anything in error log? https://prnt.sc/26qc3mk
EDIT: The plugin guys tell us that the problem is the way we call to wp-cron.
So even though Cloudron calls wp-cron every minute, I would like to call it twice a day more with the typical type of call from the cron tab. Something like:
0 */12 * * * /usr/bin/php -q /public/wp-cron.php >/dev/null 2
This is the type of call that the plugin needs. It's possible?
We are interested in this image optimization plugin because it optimizes images in the cloud without a limit of megabytes. I have to try to make it work.
If you know of another plugin that does the same and works on cloudron, we can switch.
-
@mdreira We use WP CLI to run cron jobs like so:
sudo -u www-data -i -- /app/pkg/wp --skip-themes --path=/app/data/public/ cron event run --due-now
Are you able to run the command above manually and see if it produces the error message ? Also, remove the
--skip-themes
and check if that helps as well, maybe that's causing the problem. TBH, I am not 100% sure why we have--skip-themes
there, it should probably be removed. -
@girish Here I send you the screenshot of the terminal after sending those commands:
Running it like this did not make the plugin work.
The plugin cron task is this:
When the cron executes this task it gives me this error:
Is there any other way to execute that task? I have to get that plugin working. The plugin people don't know what's going on because our cloudron server is something special
-
@girish The plugin is optimizador.io (https://optimizador.io/)
Right now I edit the links of the screenshots and upload the images directly.
-
-
@mdreira It seems that global variables are not working. The clue is from this error message:
WordPress database error Table 'c801e5ebba2fb24b.wp_' doesn't exist for query SELECT * FROM wp_ WHERE meta_id = 6 AND thumb_size = 'we_original_size' ORDER BY time DESC made by include('phar:///app/pkg/wp/php/boot-phar.php'), include('phar:///app/pkg/wp/vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->run_command_and_exit, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, Cron_Event_Command->run, Cron_Event_Command::run_event, do_action_ref_array('my_schedule_hook'), WP_Hook->do_action, WP_Hook->apply_filters, oiwe_my_schedule_function, oiwe_optimize_concurrent_image_by_att_id, oiwe_isOptimized
The relevant code is:
function oiwe_get_optimization_data_by_attID($id){ global $wpdb; global $OIWE_TABLENAME; $table_name = $wpdb->prefix . $OIWE_TABLENAME ; $querystr = " SELECT * FROM $table_name WHERE meta_id = $id AND thumb_size = 'we_original_size' GROUP BY uuid ORDER BY time DESC "; $optimizations = $wpdb->get_results($querystr, OBJECT); return $optimizations ; }
In the above,
OIWE_TABLENAME
isnull
. In fact, all the globals in that file are "null" which is why we later get the error that string is expected. My PHP skillz are being put to test... -
So strange, I cannot figure why this is. There is a constants.php in the plugin. I put the logs below:
<?php $OIWE_API_URL = "http://apiv1.optimizador.io:80/"; global $OIWE_API_URL ; $PLUGIN_VERSION = "1.0.22"; error_log('The version is ' . $PLUGIN_VERSION); global $PLUGIN_VERSION; error_log('The version is now ' . $PLUGIN_VERSION); $OIWE_TABLENAME = "imgoptimizations"; global $OIWE_TABLENAME;
Now, if I run via PHP cli:
root@d2c84f40-ba29-47fd-87a5-48c873006e89:/app/data# php /app/data/public/wp-content/plugins/weimgoptimizer/includes/constants.php The version is 1.0.22 The version is now 1.0.22
So, the above works as expected. But if I now run this via WP CRON:
root@d2c84f40-ba29-47fd-87a5-48c873006e89:/app/code# sudo -u www-data -i -- /app/pkg/wp --path=/app/data/public/ cron event run my_schedule_hook The version is 1.0.22 The version is now
The version is empty for the second one! In fact, all the global things like
global $PLUGIN_VERSION;
in constants.php become immediately empty . FWIW, theglobal
usage above seems to be incorrect. In PHP AFAIK,global
is to declare that you are going to use a global variable and not that a variable has to become global.