• Resolved rainelement

    (@rainelement)


    I’m trying to use your plugin’s Worker Mode with a custom Worker script to implement advanced multi-currency caching at the Cloudflare edge for my WooCommerce site.

    I have followed the FAQ guidance and defined the SWCFPC_CF_WORKER_FULL_PATH constant in my wp-config.php file, pointing to the absolute server path of my merged custom Worker script (which combines your worker_template.js logic with my necessary modifications for varying the cache key based on CF-IPCountry and a currency-specific cookie).
    Example: define(‘SWCFPC_CF_WORKER_FULL_PATH’, ‘/home/662214.cloudwaysapps.com/chyneruzzn/public_html/wp-content/my-custom-worker.js’);

    The Problem:
    Despite having the constant correctly defined (with WORKER, not WOKER), the plugin does not appear to be deploying my custom Worker, nor its own default Worker. My Cloudflare dashboard (Workers & Pages for minoar.com) shows no Worker service deployed by your plugin. The plugin’s internal logs consistently show it managing/updating a Cloudflare Cache Rule, indicating it’s operating in a Cache Rule mode, not Worker mode.

    Troubleshooting Steps Taken & Findings:

    1. Initial Typo in Plugin Code: Using Query Monitor, I initially found a warning: Warning: Undefined array key “swcfpc_cf_woker_enabled” in …/wp-cloudflare-page-cache/libs/backend.class.php:342. I manually corrected this typo (and others found via string search) from woker to worker in the plugin’s PHP files.
    2. New Warning After Fix: After correcting the typo in the PHP files and re-saving plugin settings, the Query Monitor warning changed to: Warning: Undefined array key “swcfpc_cf_worker_enabled” (now with the correct spelling) at the same location. This suggests the plugin is now looking for the correctly spelled option, but this option is not being properly initialized or saved in the WordPress database via the plugin’s UI.
    3. No UI Option for Worker Mode: I have thoroughly checked all tabs and settings within the plugin (including “Advanced Settings” and the initial Cloudflare API connection tab). I cannot find an explicit UI toggle or selection to switch between “Page Rule Mode” and “Worker Mode.” The main “Enable Cloudflare CDN & Caching” toggle (which mentions “using Cache Rule” in its description) does not seem to trigger Worker deployment even after the PHP typo fixes and with the wp-config.php constant set.
    4. Overwrite cache-control header… Setting: I have ensured the setting “Overwrite the cache-control header for WordPress’s pages using web server rules” is set to NO (Disabled), as its description states it “must be disabled if enabled the Workers mode option.”
    5. API Connection: The plugin is successfully connected to my Cloudflare account (using both Global API Key and a correctly permissioned API Token for testing) and correctly identifies my minoar.com zone. It can purge cache successfully.

    My Questions:

    1. How can I definitively enable/trigger Worker Mode within the plugin so that it attempts to deploy a Worker and respects the SWCFPC_CF_WORKER_FULL_PATH constant for using a custom script? Is there a hidden setting, a specific sequence of actions, or a known issue with the UI for selecting Worker Mode?
    2. Given the “Undefined array key swcfpc_cf_worker_enabled” warning (after fixing the woker typo in your PHP), how can I ensure this option is correctly saved to the database so the plugin recognizes that Worker Mode is intended/enabled?

    I believe the core issue might be related to how the swcfpc_cf_worker_enabled option is set or read internally, preventing the plugin from switching to Worker Mode and utilizing the custom worker path.

    Any guidance you can provide would be greatly appreciated. I’m keen to use the Worker functionality for my site’s specific caching needs.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter rainelement

    (@rainelement)

    Hi SPC Team,

    Following up on my previous inquiries regarding Worker Mode and using the SWCFPC_CF_WORKER_FULL_PATH constant.

    Progress & New Findings:

    1. Custom Worker Script IS Being Deployed to Cloudflare:
      • After some investigation, including temporarily modifying plugin PHP files to correct an internal typo from swcfpc_cf_woker_enabled to swcfpc_cf_worker_enabled, and ensuring my wp-config.php has define(‘SWCFPC_CF_WORKER_FULL_PATH’, ‘/actual/path/to/my/custom_merged_worker.js’); correctly set, I can confirm that when I toggle “Enable Cloudflare CDN & Caching” OFF and then ON in the plugin settings, new Worker services are created in my Cloudflare account (“Workers & Pages”).
      • The code within these deployed Worker services is correctly my custom merged script (which integrates your worker_template.js with my specific cache key modifications). I have seen multiple instances created from repeated toggles.
    2. HTTP Route Creation is FAILING:
      • Despite the Worker scripts being deployed to Cloudflare, none of them are having an HTTP Route (e.g., *.example.com/*) successfully assigned to them by the plugin. They only possess their default *.workers.dev routes and thus are not active for my main domain.
      • My WordPress Query Monitor captures a failed API call when the plugin attempts to enable caching:
        POST https://api.cloudflare.com/client/v4/zones/%5BMY_ZONE_ID%5D/workers/routes results in a 400 Bad Request.
      • The Cloudflare error typically associated with this (from previous generic testing of such scenarios) is often (err code: 10007) This Worker does not exist on your account. This error occurs when attempting to create a route for a worker script name that Cloudflare cannot find or does not recognize as existing for that zone.
    3. Database Option:
      • To ensure the plugin recognized the (now correctly spelled) swcfpc_cf_worker_enabled flag, I also had to use a PHP snippet to directly update the corresponding key in the plugin’s swcfpc_config option in the database to an “enabled” state, as the UI did not seem to save this correctly after the PHP file typo corrections.

    Current Situation:
    My custom Worker script is being successfully uploaded to Cloudflare by your plugin when triggered. However, the crucial subsequent step of your plugin creating an HTTP Route to direct traffic from example.com to this deployed worker is failing.

    Request:

    1. Could you please advise on why the POST …/workers/routes API call might be consistently failing with a 400 Bad Request (likely due to error 10007, indicating the worker script name used in the route creation call doesn’t match an existing script)?
    2. Is there a specific internal naming convention or process the plugin uses for the Worker script name during deployment that might differ from what it then tries to reference when creating the route, especially when SWCFPC_CF_WORKER_FULL_PATH is active?
    3. Are there any other plugin settings or known conditions that could interfere with successful route creation by the plugin?

    I am using a correctly permissioned Cloudflare API Token for the connection (with Workers Scripts: Edit, Workers Routes: Edit, Zone: Read, Cache Purge, etc., for the specific zone). My example.com zone is correctly selected in your plugin settings.

    Thank you for your assistance in resolving this route creation issue to get Worker mode fully operational with a custom script.

    Plugin Support Kush

    (@kushnamdev)

    Hi @rainelement,

    Thank you for reaching out to us.

    Please note that the Workers feature has been removed to simplify the plugin’s functionality, as the current approach is more efficient and beneficial for the majority of users. However, if you wish to continue using Workers, you may revert to an older version of the plugin.

    We understand that these updates may have impacted your website’s caching behavior, and we sincerely apologize for any inconvenience this may have caused.

    To better understand these changes and their impact on your setup, we recommend reviewing the latest release notes and plugin documentation.

    Your feedback is incredibly valuable to us, and we are committed to providing a seamless experience. If you have any additional concerns or questions, please feel free to reach out to our support team.

    Best regards,

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Issue Enabling Worker Mode & Using SWCFPC_CF_WORKER_FULL_PATH’ is closed to new replies.