• Resolved Tejas Khatri

    (@tejaskhatri)


    What We Are Trying to Do

    We have a custom REST API endpoint registered via functions.php to:

    • Accept a token and email.
    • Verify them.
    • Return a newly generated token for a third-party system.

    🧩 Custom Code Used in functions.php

    • A REST route is created: api/authwork/tokenwork/
    • Code verifies:
      • Token presence and match.
      • Email existence.
      • If matched, generates a new token and returns it.

    ⚠️ Problem Faced

    • After enabling both the following plugins:
      • http-requests-manager
      • the-events-calendar
    • AND placing the above code in functions.php,
      • Any request to wp-json endpoint leads to an infinite loop.
      • This causes server memory exhaustion.

    🐞 Error Logged in debug.log

    PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 2097152 bytes) in wp-content/plugins/http-requests-manager/http-requests-manager.php on line 2570
    

    🧪 Initial Findings

    • The infinite loop occurs only when:
      • Both plugins are active.
      • Custom REST code is placed in the theme’s functions.php.
    • Removing either plugin OR the custom code resolves the issue.
    • Likely culprit is how one plugin hooks into HTTP requests or the REST API.

    📌 Need Support Team To Help With

    • Investigate conflicts or recursive hooks triggered by:
      • http-requests-manager‘s HTTP interception.
      • Custom REST endpoint triggering internal REST calls indirectly.
    • Provide any temporary workaround, such as:
      • Code-level exclusion to not track this specific route inside http-requests-manager.
      • Filters or action deregistration advice.
    • Suggest best practice for such custom API implementation when plugins manage HTTP or REST hooks.
    • Curl Call:

    curl --location 'http://localhost/wordpress-test/wp-json/api/authwork/tokenwork?email=thetechopd%40gmail.com' \
    --header 'Authorization: Bearer xcsdvssdvsdvssvd'

Viewing 1 replies (of 1 total)
  • Plugin Author veppa

    (@veppa)

    Hello,

    I assume that you are using http-requests-manager plugin in “Smart block” operation mode. In that case you can explicitly allow WP_HTTP external requests that cause infinite loop.

    First check what requests are being blocked too many times in “Tools” -> “HTTP Requests Manager” page.

    Use “group by page type” from dropdown to see on which page type too many blocking happens.
    Use “group by request domain” from dropdown to see on which domain too many blocking happens.

    I do not see logs from that page in you report so I can assume following values.

    Most blocking happens on “rest_api” page type to “SOMEDOMAIN.com” domain. Using this data you can create following custom rule:

    1. Navigate to “Settings” tab in “Tools” -> “HTTP Requests Manager” page
    2. Make sure operation mode is “Smart block”.
    3. Click “Add new” button next to ‘Custom rules for “Smart Block” mode’ text.
    4. Create following rule:
      What -> “domain” -> “SOMEDOMAIN.com”,
      Where -> “rest_api”,
      Action -> “Allow”,
      Then click “Save changes” button.

    This should prevent blocking particular external request and avoid infinite loop caused by “custom code” or “other plugin”.

    View tutorial to explicitly allow some external WP_HTTP requests.

    Why infinite loop happens?

    1. http-requests-manager plugin blocks some WP_HTTP requests based on “operation mode”.
    2. “Other plugin” or “custom code” expects successful response from remote WP_HTTP request. When request is not valid then it tries to get valid response and sends external request again and again (infinite times).

    Optimal solution should be optimizing “Other plugin” or “custom code” to avoid infinite loop. Because any external request can fail due to network or server error. And that failure should not create infinite loop.

Viewing 1 replies (of 1 total)

The topic ‘Infinite Loop & Memory Exhaustion with Two Plugins and Custom Code’ is closed to new replies.