Skip to content

Conversation

@aatanasov-cloudinary
Copy link
Collaborator

@aatanasov-cloudinary aatanasov-cloudinary commented Jul 17, 2025

Fixes this PHP warning:

PHP Warning:  file_get_contents(/cloudinary/app/public/wp-content/uploads/cron/cron-run.txt): Failed to open stream: No such file or directory in /cloudinary/app/public/wp-content/plugins/cloudinary_wordpress/php/cron/class-lock-file.php on line 41

Approach

  • Ensure file_get_contents is used when the file exists.

QA notes

  • Ensure you have the debug mode of your WordPress instance enabled.
  • Go to /wp-admin/admin.php?page=cloudinary&section=cron_system
  • Enable the cron (all options).
  • Wait for the first run.
  • Check debug.log
  • The warning shouldn't appear.

$data = file_get_contents( $lock_file ); // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown

if ( ! file_exists( $lock_file ) ) {
return '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do we risk encountering another PHP warning when this is called? I noticed this function is called in this place right now https://github.com/cloudinary/cloudinary_wordpress/blob/master/php/class-cron.php#L392-L394

and that function is doing a foreach, which on an empty string would return a PHP warning. Not sure how to replicate this scenario though.

Perhaps we can simply add another check before that foreach?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gabrielcld2, thank you for that. I agree, and added the additional check.

@aatanasov-cloudinary aatanasov-cloudinary merged commit 27ac0f5 into develop Jul 23, 2025
4 checks passed
This was referenced Aug 6, 2025
@aatanasov-cloudinary aatanasov-cloudinary deleted the fix/cron-run-txt-warning branch September 17, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants