CodeIgniter Forums
Spark command not working in controller after upgrade to CI 4.5.2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Spark command not working in controller after upgrade to CI 4.5.2 (/showthread.php?tid=91137)

Pages: 1 2


RE: Spark command not working in controller after upgrade to CI 4.5.2 - InsiteFX - 06-22-2024

I'm using Laragon with apache 2.4.59-240605 & MySQL 8.3 PHP 8.3 CI 4.5.2

I switched to Laragon because XAMPP is not being updated that much any more.


RE: Spark command not working in controller after upgrade to CI 4.5.2 - jetspeed - 06-22-2024

(06-22-2024, 02:16 AM)kenjis Wrote: This code is invalid.
PHP Code:
log_message('after''before service(commands)'); 

There is no log level `after`.
https://codeigniter.com/user_guide/general/common_functions.html#log_message

Yeah, that's obviously a typo, but that line was never executed anyway. It should have read:
 
PHP Code:
log_message('debug''after service(commands)'); 



RE: Spark command not working in controller after upgrade to CI 4.5.2 - jetspeed - 06-22-2024

So after more debugging, I lucked into finding the problem.

It seems CodeIgniter\CLI\Commands->discoverCommands() was loading vendor\codeigniter4\framework\system\Commands\Server\rewrite.php

This caused it to rewrite to localhost anytime command() was called within a controller.

Delving into rewrite.php, I see that there is a check to not do the rewrite when in cli. However when running a cli command within a controller on xammp, PHP_SAPI is not 'cli' but 'apache2handler'.

So if I crudely fix it as below, it works. I'm not sure what changes has been made since CI 4.4.6 that would result in this new behaviour? Can someone with more knowledge of the framework please check?

PHP Code:
// Avoid this file run when listing commands
if (PHP_SAPI === 'cli' || PHP_SAPI === 'apache2handler') {
    return;




RE: Spark command not working in controller after upgrade to CI 4.5.2 - kenjis - 06-24-2024

@jetspeed I have confirmed the behavior, and sent a PR to fix it.
Check https://github.com/codeigniter4/CodeIgniter4/pull/8995


RE: Spark command not working in controller after upgrade to CI 4.5.2 - datamweb - 06-24-2024

@jetspeed thank you!


RE: Spark command not working in controller after upgrade to CI 4.5.2 - jetspeed - 06-24-2024

(06-24-2024, 12:55 AM)kenjis Wrote: @jetspeed I have confirmed the behavior, and sent a PR to fix it.
Check https://github.com/codeigniter4/CodeIgniter4/pull/8995
Thank you so much!