Welcome Guest, Not a member yet? Register   Sign In
Output is filled with warning data
#1

(This post was last modified: 09-22-2018, 03:32 AM by richb201.)

I have figured out that the problem I am having (only on the Linux machine) is due to 

PHP Code:
$json=json_encode($table);          
$output
$this->output
                
->set_content_type('application/text')
 
               ->set_header("Access-Control-Allow-Origin""*")
 
                ->set_output($json); 
the above code (at the bottom of the function, btw) is pushing all kinds of Warning data into the Output buffer, before my actual $json. When my javascript code on the other side gets it, it gets confused, tries to parse it, and this causes the server 500 error that has been killing me. 

Originally on Windows server version, I used  ->set_content_type('application/json') instead. This doesn't seem to work on the Linux server so I changed it to ->set_content_type('test/plain'). Now I can send the data but I the problem is that now I get a full load of warning messages in the output buffer. Two questions:

1. How can I check the actual buffer with my debugger before it goes out? 
2. How come application/json won't work on my Linux server?
3. If I am stuck with application/text how can I make sure CI doesn't stuff other junk data into the buffer?

I have attached the buffer as it was transmitted back to the client. 

Attached Files
.txt   output_buffer.txt (Size: 42.54 KB / Downloads: 22)
proof that an old dog can learn new tricks
Reply
#2

Did you try:

PHP Code:
->set_content_type('application/json'
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 09-22-2018, 08:07 AM by richb201.)

Yeah that is exactly what I had. It wasn't working on linux so I took a look at the text in a file you sent me the link for:

The only allowed values for the Content-Type header are:
application/x-www-form-urlencoded
multipart/form-data
text/plain

However, I changed it back to what should work:

$output= $this->output
   ->set_content_type('application/json')
   ->set_header("Access-Control-Allow-Origin", "*")
   ->set_output(json_encode($table));


The data seems to come across fine except it is appended to the junk in the attached file still. I had a similair issue a few months ago and the answer was to have the buffer be sent by a separate page. In this situation there is no UI, this is merely a daemon that talks to the chrome Extension. How can I purge the output buffer prior to sending?
proof that an old dog can learn new tricks
Reply
#4

According to MDN that's the way you should do it from it's own page.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(09-22-2018, 08:52 AM)InsiteFX Wrote: According to MDN that's the way you should do it from it's own page.

Something else is wrong then.
proof that an old dog can learn new tricks
Reply
#6

here are the buffers just after the Output function. They seem OK?

and here is the buffer that arrives in the browser.

As you can see, either chrome or CI added all that 'junk" to the buffer. My guess is CI since their are line numbers from my CI program in that buffer. Why is CI/PHP adding this junk? At the very end of the buffer (buf.txt) you can see my actual text.     

CI bug???

Attached Files
.txt   buf.txt (Size: 21.27 KB / Downloads: 24)
proof that an old dog can learn new tricks
Reply
#7

(This post was last modified: 09-22-2018, 12:21 PM by InsiteFX.)

Well from the code in your file it is saying that you have an error in your controller on
line 180 and also that it could not fetch from MySQLi.

What's the code in your controller Subit_backend.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

Line 180 is the headers list()

$output= $this->output
->set_content_type('application/json')
->set_header("Access-Control-Allow-Origin", "*")
->set_output(json_encode($table));
$headers=headers_list();

I put that in there to prove to myself that the headers were OK, which they are.
proof that an old dog can learn new tricks
Reply
#9

This is what it is saying.

Code:
A PHP Error was encountered Severity: Warning Message:  Subit_backend::register(): Property access is not allowed yet
Filename: controllers/Subit_backend.php Line Number: 180
Backtrace: File: /opt/bitnami/apache2/htdocs/sub_crud/application/controllers/Subit_backend.php
Line: 180 Function: _error_handler File: /opt/bitnami/apache2/htdocs/sub_crud/index.php
Function: require_once

Looks like your require once file is trying to access a property before it is available.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(This post was last modified: 09-23-2018, 08:18 AM by richb201.)

Well, it is a warning, not an error. I can live with warnings if they don't show up in my reply buffer Smile. I switched over to a GET instead of a POST. That made the 500 error go away. As I said, this code has worked fine under Windows for months.

How can I get rid of the junk in the buffer? Can I somehow output the junk to "space" to flush the buffer? I couldn't find a command in CI to flush. Perhaps php has one?

I am going to try ob_clean(). Any chance that will work if I place it right before the output?
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB