Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Long Polling: Stuck in while loop

PHP is not a multi tasking language, you should not try to use it as such. In other words, long polling is not something you should try to even attempt unless you use a language construct designed to support it.

Specifically to your question, you probably fail because wordpress has the habit of caching in memory as mach info that is retrieved from the DB as it can (this is core feature, no plugins involved). To the best of my memory once post metadata is retrieved it is cached and therefor get_post_meta( $post_id, 'last_modified', true ) always returns the same value. You need to invalidate the cache to be able to do what you are trying to, or send a query to the DB bypassing the WP API.

In addition your code has very bad influence on the performance of the server as you get one apache process busy without doing anything useful, which if you have the apache to run 10 processes means that you can serve 10% less requests at the time your code is working.

Another factor is the php execution time limit which is usually set to 30 seconds, therefor your long polling process will just die after 30 seconds without giving you any notification about it.

Related Posts:

  1. How to update Comment post meta through an Ajax call
  2. Update attachment metadata fails
  3. Attach time/date stamp on add_post_meta
  4. bulk update meta value with ajax
  5. Update status, meta while inside a post using AJAX button
  6. Filter images from media library by guid meta field
  7. Want to send ajax request in wordpress to a custom file in plugin
  8. delete post meta data in array WordPress
  9. Allow guest to update custom post met using ajax
  10. Data from ajax not updating post meta
  11. delete attachment for one post without deleting actual attachment post
  12. Why use wp_send_json() over echo json_encode()?
  13. Why not register shortcodes if is_admin dashboard?
  14. post formats – how to switch meta boxes when changing format?
  15. Multiple ajax nonce requests
  16. Contact Form 7 Custom Post Action
  17. How to properly use wp.ajax.post?
  18. AJAX vs Fragment Caching for W3 Total Cache [closed]
  19. Delete row of custom table in WordPress using AJAX
  20. jQuery Autocomplete in WordPress
  21. Change theme based on window size
  22. help on wp_editor via ajax load [duplicate]
  23. Class WP_Rewrite not found
  24. How to allow to user non logged in WP system upload in media library?
  25. WordPress function to get term or post object by id
  26. Help add ajax load more button
  27. Conditional success callback based on Ajax Response not working
  28. admin-ajax.php slow, how to speed it up?
  29. I’m getting a 401 while calling the wp-json endpoint via ajax
  30. Unable to parse JSON response from wp_send_json_success [closed]
  31. Keep getting 400 Bad Request error when trying out AJAX on custom theme
  32. problem with WordPress ajax
  33. Ajax custom search not functioning as expected
  34. Jetpack Infinite Scroll – Add more than 7 posts each time?
  35. Speed/Performance difference between `wp_ajax` and `init` checks for AJAX/POST requests?
  36. How to handle 400 status in Ajax [duplicate]
  37. Remove trailing 0 from function that is used both statically and dynamically
  38. How to load next and previous posts by Ajax
  39. Nonce fails on ajax save
  40. WordPress ajax works on FF but not on IE & chrome
  41. Disallow second login session
  42. WordPress P2 live problem
  43. Save & Reset button in theme-option with Ajax (without refresh)
  44. Ajax Multi Response Problem
  45. AJAX call inside plugin class not triggering
  46. Custom AJAX Endpoint not returning any result
  47. Contact form 7 Hide response messages after 5 seconds
  48. WordPress Heartbeat API cannot parse data
  49. how should i get json encoded data from wordpress ajax action page
  50. Cache plugins and ajax nonce verification
  51. Ajax function on #publish only saves as draft – how to make it publish?
  52. AJAX call broken after actualization
  53. How to include php-generated javascript?
  54. Serve a different theme based on window size
  55. custom autocomplete search
  56. Ajax function not returning any results
  57. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  58. ajax problem – function on server is not called
  59. wp_mail doesn’t work when logged in?
  60. Need help with Access-Control-Allow-Origin
  61. Send email via ajax
  62. wp_ajax handler with multiple class instances
  63. admin-ajax.php (aborted) error when using jQuery.get
  64. Load page HTML content through AJAX
  65. problem using ajax url
  66. Problems implementing Load More functionality
  67. admin-ajax.php error 500
  68. How to display contact form 7 form in vanilla js without jquery in frontend
  69. Error sending array data from php to javascript
  70. Sharing variables in both actions wp_footer and wp_ajax
  71. Display full WordPress post under search form using AJAX
  72. Ajax callback not work
  73. WordPress Select Option Load Custom Fields
  74. jQuery.post returns 0
  75. Opening Modal popup on Ajax form submission
  76. Ajax sometimes work and sometimes just don’t work
  77. admin-ajax error 400
  78. wordpress admin ajax trash_comment
  79. Failed to load resource: the server responded with a status of 404 (Not Found) admin-ajax.php
  80. Javascript output now showing in custom widget
  81. Create a post with REST API and adding a category
  82. how to correctly use json_encode with ajax
  83. How to trigger lost password email using REST API?
  84. Display post thumbnail after clicking on post id with AJAX
  85. Using AJAX on Contact-form the WordPress way
  86. Retrieve Header Background Image with AJAX
  87. How to block search engines indexing certain AJAX actions
  88. AJAX call in backend results in empty update_option
  89. Ajax Comment: Page reloads whenever the comment submission form is reloaded
  90. wp_ajax_action, wp_ajax_nopriv_action not working
  91. get_comments() returns empty array if called through AJAX
  92. Manually cache a special, non-WP-but-using-WP page (e.g. Ajax results) with W3TC
  93. change attachment custom field onChange event
  94. Is it a good idea to init ajax functions only while ‘DOING_AJAX’
  95. How to get parent comment’s id?
  96. Static var overwritten with WP AJAX action, works fine without AJAX
  97. using ajax to query sql
  98. Adding custom fields to Wired Impact Volunteer Management Plugin
  99. How to update my jquery/PHP function to add/remove user as favorites in (WordPress) users list
  100. randomly get 400 error while user is logged in wp_ajax
Categories ajax Tags ajax, post-meta
How can I dynamically add a post to a custom post type which uses a custom field?
API Hook for After Commenting (for sharing on Facebook)

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress