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

Component build json output #39341

Closed
JamesShaver opened this issue Dec 1, 2022 · 8 comments
Closed

Component build json output #39341

JamesShaver opened this issue Dec 1, 2022 · 8 comments

Comments

@JamesShaver
Copy link
Contributor

Steps to reproduce the issue

Build a component view for json formatted output.

URL:

http://localhost/joomla/index.php?option=com_testcomponent&view=json&format=json

site\src\View\Json\JsonView.php:
<?php

namespace Joomla\Component\Testcomponent\Site\View\Json;

use Joomla\CMS\MVC\View\JsonView as BaseJsonView;

class JsonView extends BaseJsonView
{
    public $json;
    
    public function display($tpl = null)
    {
        $array = [
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3',
            'key4' => 'value4'
        ];
        $this->json = json_encode($array);
        
        parent::display($tpl);
    }
}
site\tmpl\json\json.php:
<?= $this->json; ?>

Expected result

{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}

Actual result

<br />
<b>Warning</b>:  session_write_close(): Failed to write session data using user defined save handler. (session.save_path: \Users\username\OneDrive\Documents\Development\xampp\tmp) in <b>C:\Users\username\OneDrive\Documents\Development\xampp\htdocs\joomla\libraries\vendor\joomla\session\src\Storage\NativeStorage.php</b> on line <b>114</b><br />

System information (as much as possible)

MS Windows 11
XAMPP for Windows 8.1.12
Apache/2.4.54 (Win64)
PHP Version 8.1.12

Additional comments

Debug mode is turned on, but nothing populates in everything.php

@Irata
Copy link
Contributor

Irata commented Dec 1, 2022

I am seeing the same messages, intermittently, about failing to write the session when invoking a controller via JS that passes to and is returned JSON.

url = 'index.php?option=com_mycomponent&task=mycontroller.incoming&format=json';

my controller does almost nothing

public function incoming()
	{
		$barney = $this->app->input->post->get('payload', '', 'array');
		$response = new JsonResponse($barney);
		echo $response;
	}

Reloading the page resolves the issue for awhile but its return is seemingly random.

I don't have anymore diagnostics than already supplied at this stage.

PHP Version 8.0.23
Web Server Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.0.23
WebServer to PHP Interface apache2handler
Joomla! Version Joomla! 4.2.5 Stable [ Uaminifu ] 8-November-2022 15:00 GMT

Running on a local LAMP stack.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39341.

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Dec 2, 2022

This is coming from recent changes in debug plugin. When Track Request History option is disabled, an unlimited number of request data is stored in the session until a HTML page is opened.

@JamesShaver
Copy link
Contributor Author

Confirmed, enabling Track Request History removes the error message.

@richard67
Copy link
Member

@SharkyKZ So it’s a bug, right?

@MacJoom
Copy link
Contributor

MacJoom commented Dec 9, 2022

Steps to reproduce the issue

Build a component view for json formatted output.

URL:

http://localhost/joomla/index.php?option=com_testcomponent&view=json&format=json

site\src\View\Json\JsonView.php:
<?php

namespace Joomla\Component\Testcomponent\Site\View\Json;

use Joomla\CMS\MVC\View\JsonView as BaseJsonView;

class JsonView extends BaseJsonView
{
    public $json;
    
    public function display($tpl = null)
    {
        $array = [
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3',
            'key4' => 'value4'
        ];
        $this->json = json_encode($array);
        
        parent::display($tpl);
    }
}
site\tmpl\json\json.php:
<?= $this->json; ?>

Expected result

{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}

Actual result

<br />
<b>Warning</b>:  session_write_close(): Failed to write session data using user defined save handler. (session.save_path: \Users\username\OneDrive\Documents\Development\xampp\tmp) in <b>C:\Users\username\OneDrive\Documents\Development\xampp\htdocs\joomla\libraries\vendor\joomla\session\src\Storage\NativeStorage.php</b> on line <b>114</b><br />

System information (as much as possible)

MS Windows 11 XAMPP for Windows 8.1.12 Apache/2.4.54 (Win64) PHP Version 8.1.12

Additional comments

Debug mode is turned on, but nothing populates in everything.php

I cannot reproduce the issue with your code since JsonView doesnt apply any template code. So the output is always empty... tmpl\json\json.php is never called. parent::display just puts this->_output into the documents buffer. $this->json is not used.
I can think of a problem where the session data is growing too much, but cannot reproduce the issue right now.
Please post the complete code with this issue - Thank you

@richard67
Copy link
Member

@MacJoom Which PHP version have you used when trying to reproduce the issue? Was it 7.4? Possibly the issue happens only with PHP 8.x.

@richard67
Copy link
Member

I have found another thing which happens with PHP 8 which happens when the "Track Request History" option in the "Debug" system plugin is disabled and disappears when that option is enabled. See #39403 . It seems they have the same root cause, but I wanted the symptoms to be documented and so created that other issue.

@richard67
Copy link
Member

Closing as having a pull request. Please test #39526 . Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants