[wp-trac] [WordPress Trac] #57475: wp_schedule_event function causes "Headers already sent" error

WordPress Trac noreply at wordpress.org
Mon Jan 16 21:46:38 UTC 2023


#57475: wp_schedule_event function causes "Headers already sent" error
------------------------------+------------------------------
 Reporter:  onetarek          |       Owner:  (none)
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Cron API          |     Version:  6.1.1
 Severity:  normal            |  Resolution:
 Keywords:  has-testing-info  |     Focuses:
------------------------------+------------------------------

Comment (by peterwilsoncc):

 The warnings in your logs are occurring when the cron job
 `test_daily_event_hook` runs, they're not running due to the call to
 `wp_schedule_event()`.

 Calls to wp-cron.php send the headers early in the request. The
 unconditional call to start the session in your plugin will then attempt
 to start a session on the wp-cron.php request.


 {{{
 [16-Jan-2023 21:36:55 UTC] PHP Stack trace:
 [16-Jan-2023 21:36:55 UTC] PHP   1. {main}() /vagrant/wordpress-
 develop/src/wp-cron.php:0
 [16-Jan-2023 21:36:55 UTC] PHP   2. require_once() /vagrant/wordpress-
 develop/src/wp-cron.php:46
 [16-Jan-2023 21:36:55 UTC] PHP   3. require_once() /vagrant/wordpress-
 develop/src/wp-load.php:50
 [16-Jan-2023 21:36:55 UTC] PHP   4. include() /vagrant/wordpress-
 develop/src/wp-config.php:9
 [16-Jan-2023 21:36:55 UTC] PHP   5. require_once() /vagrant/wp-
 config.php:147
 [16-Jan-2023 21:36:55 UTC] PHP   6. include_once() /vagrant/wordpress-
 develop/src/wp-settings.php:447
 [16-Jan-2023 21:36:55 UTC] PHP   7. session_start()
 /vagrant/content/plugins/cron-test-plugin/plugin.php:24
 }}}

 WP-cron doesn't support headers or sessions as it can be run either within
 the browser or via the CLI. I suggest you wrap the call to
 `session_start()` in a conditional to ensure it only runs in browser
 requests.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57475#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list