Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not start session when running under WP-CLI #135

Merged
merged 1 commit into from
Oct 5, 2018

Conversation

christianwach
Copy link
Member

Overview

Prevents PHP warnings by skipping session_start() when running via WP-CLI.

Before

When running WP-CLI, there are situations where the Apache user has permissions that the Shell user does not, which can result in the following warnings:

$ wp plugin update civicrm-admin-utilities
PHP Warning:  session_start(): open(xxx.xx.xxx.xx:11211/sess_ncos60tkmhud8phq94hjco6as4, O_RDWR) failed: No such file or directory (2) in /path/to/wp-content/plugins/civicrm/civicrm.php on line 305
Warning: session_start(): open(xxx.xx.xxx.xx:11211/sess_ncos60tkmhud8phq94hjco6as4, O_RDWR) failed: No such file or directory (2) in /path/to/wp-content/plugins/civicrm/civicrm.php on line 305
Success: Plugin already updated.
PHP Warning:  Unknown: open(xxx.xx.xxx.xx:11211/sess_ncos60tkmhud8phq94hjco6as4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: open(xxx.xx.xxx.xx:11211/sess_ncos60tkmhud8phq94hjco6as4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (xxx.xx.xxx.xx:11211) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (xxx.xx.xxx.xx:11211) in Unknown on line 0

Please note that the above is in the context of CiviCRM running via Memcached, but the ability to write to session.save_path is common to all contexts.

After

No PHP warnings:

$ wp plugin update civicrm-admin-utilities
Success: Plugin already updated.

Technical Details

Tests for WP-CLI and skips session_start() when detected.

@kcristiano
Copy link
Member

Code only affects wp-cli and works as expected.

@kcristiano kcristiano merged commit 4c13ffc into civicrm:master Oct 5, 2018
@christianwach christianwach deleted the wpcli branch October 10, 2018 10:58
totten added a commit to totten/civicrm-wordpress that referenced this pull request Jul 3, 2020
This is a refinement of the idea in civicrm#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

```
PHP Warning:  session_start(): Cannot send session cookie - headers already sent by (output started at phar:///Users/totten/bknix/bin/cv/.box/src/Printer.php:83) in /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm.php on line 371
PHP Stack trace:
PHP   1. {main}() /Users/totten/bknix/bin/cv:0
PHP   2. require() /Users/totten/bknix/bin/cv:14
PHP   3. Civi\Cv\Application::main() phar:///Users/totten/bknix/bin/cv/bin/cv:27
PHP   4. Civi\Cv\Application->run() phar:///Users/totten/bknix/bin/cv/src/Application.php:15
PHP   5. Civi\Cv\Application->doRun() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:124
PHP   6. Civi\Cv\Application->doRun() phar:///Users/totten/bknix/bin/cv/src/Application.php:46
PHP   7. Civi\Cv\Application->doRunCommand() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:193
PHP   8. Civi\Cv\Command\UpgradeDbCommand->run() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:850
PHP   9. Civi\Cv\Command\UpgradeDbCommand->execute() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Command/Command.php:257
PHP  10. Civi\Cv\Command\UpgradeDbCommand->boot() phar:///Users/totten/bknix/bin/cv/src/Command/UpgradeDbCommand.php:39
PHP  11. call_user_func:{phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39}() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39
PHP  12. Civi\Cv\Command\UpgradeDbCommand->_boot_full() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39
PHP  13. CRM_Utils_System::loadBootStrap() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:99
PHP  14. CRM_Utils_System_WordPress->loadBootStrap() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System.php:1521
PHP  15. require_once() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/WordPress.php:600
PHP  16. require_once() /Users/totten/bknix/build/wpmaster/web/wp-load.php:37
PHP  17. require_once() /Users/totten/bknix/build/wpmaster/web/wp-config.php:97
PHP  18. do_action() /Users/totten/bknix/build/wpmaster/web/wp-settings.php:392
PHP  19. WP_Hook->do_action() /Users/totten/bknix/build/wpmaster/web/wp-includes/plugin.php:478
PHP  20. WP_Hook->apply_filters() /Users/totten/bknix/build/wpmaster/web/wp-includes/class-wp-hook.php:312
PHP  21. CiviCRM_For_WordPress->setup_instance() /Users/totten/bknix/build/wpmaster/web/wp-includes/class-wp-hook.php:288
PHP  22. session_start() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm.php:371
```

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).
kcristiano pushed a commit to tadpolecc/civicrm that referenced this pull request Jul 3, 2020
This is a refinement of the idea in civicrm/civicrm-wordpress#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).

Signed-off-by: Kevin Cristiano <kcristiano@kcristiano.com>
kcristiano pushed a commit to tadpolecc/civicrm that referenced this pull request Jul 3, 2020
This is a refinement of the idea in civicrm/civicrm-wordpress#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).

Signed-off-by: Kevin Cristiano <kcristiano@kcristiano.com>
kcristiano pushed a commit to tadpolecc/civicrm that referenced this pull request Jul 10, 2020
This is a refinement of the idea in civicrm/civicrm-wordpress#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).

Signed-off-by: Kevin Cristiano <kcristiano@kcristiano.com>
kcristiano pushed a commit to tadpolecc/civicrm that referenced this pull request Jul 15, 2020
This is a refinement of the idea in civicrm/civicrm-wordpress#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).

Signed-off-by: Kevin Cristiano <kcristiano@kcristiano.com>
bastienho pushed a commit to bastienho/civicrm-wordpress that referenced this pull request Sep 10, 2020
This is a refinement of the idea in civicrm#135 to address other CLI use-cases.

Before
-------

If I have a `wpmaster` site on on `bknix-max` (php73), and if I run `cv upgrade:db -vv`, then there are several warnings like this:

```
PHP Warning:  session_start(): Cannot send session cookie - headers already sent by (output started at phar:///Users/totten/bknix/bin/cv/.box/src/Printer.php:83) in /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm.php on line 371
PHP Stack trace:
PHP   1. {main}() /Users/totten/bknix/bin/cv:0
PHP   2. require() /Users/totten/bknix/bin/cv:14
PHP   3. Civi\Cv\Application::main() phar:///Users/totten/bknix/bin/cv/bin/cv:27
PHP   4. Civi\Cv\Application->run() phar:///Users/totten/bknix/bin/cv/src/Application.php:15
PHP   5. Civi\Cv\Application->doRun() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:124
PHP   6. Civi\Cv\Application->doRun() phar:///Users/totten/bknix/bin/cv/src/Application.php:46
PHP   7. Civi\Cv\Application->doRunCommand() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:193
PHP   8. Civi\Cv\Command\UpgradeDbCommand->run() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Application.php:850
PHP   9. Civi\Cv\Command\UpgradeDbCommand->execute() phar:///Users/totten/bknix/bin/cv/vendor/symfony/console/Command/Command.php:257
PHP  10. Civi\Cv\Command\UpgradeDbCommand->boot() phar:///Users/totten/bknix/bin/cv/src/Command/UpgradeDbCommand.php:39
PHP  11. call_user_func:{phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39}() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39
PHP  12. Civi\Cv\Command\UpgradeDbCommand->_boot_full() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:39
PHP  13. CRM_Utils_System::loadBootStrap() phar:///Users/totten/bknix/bin/cv/src/Util/BootTrait.php:99
PHP  14. CRM_Utils_System_WordPress->loadBootStrap() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System.php:1521
PHP  15. require_once() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/WordPress.php:600
PHP  16. require_once() /Users/totten/bknix/build/wpmaster/web/wp-load.php:37
PHP  17. require_once() /Users/totten/bknix/build/wpmaster/web/wp-config.php:97
PHP  18. do_action() /Users/totten/bknix/build/wpmaster/web/wp-settings.php:392
PHP  19. WP_Hook->do_action() /Users/totten/bknix/build/wpmaster/web/wp-includes/plugin.php:478
PHP  20. WP_Hook->apply_filters() /Users/totten/bknix/build/wpmaster/web/wp-includes/class-wp-hook.php:312
PHP  21. CiviCRM_For_WordPress->setup_instance() /Users/totten/bknix/build/wpmaster/web/wp-includes/class-wp-hook.php:288
PHP  22. session_start() /Users/totten/bknix/build/wpmaster/web/wp-content/plugins/civicrm/civicrm.php:371
```

After
-----

It doesn't try to start session in CLI (where sessions don't make sense).
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.

2 participants