Codeigniter header already sent error using json header
Getting this error when moving from development server to staging server and getting this error.
Severity: Warning --> Cannot modify header information - headers already sent
The error shows up if you are doing all of the following.
1. Change header using
$this->output->set_content_type('application/json');
2. Outputting using echo (which is not recommended by Codeigniter).
3. In php.ini, have output_buffering set very small, like 0.
Solution
There are two solutions to this issue.
1. Increase the output_buffering enough so to buffer your echo. (this is a hack)
2. Recommended solution is to replace echo with CIs built in $this->output->set_output('content') method.
Android making https requests with SSL from GoDaddy – No peer certificate error
Another hair pulling session that all ended well.
Task:
Make a secure call to a server using a httprequest and get the httpresponse for further processing.
Android http request and response:
HttpClient client = new DefaultHttpClient();
HttpGet req = new HttpGet("https://www.example.com");
HttpResponse res = client.execute(req);
Error:
javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
Problem:
The issue is that cert from GoDaddy was installed but not installed completely. An Intermediate cert is required for the server/domain in order to have a fully installed cert.
Reference:
Codeigniter running into some major growth issues
I have been using Codeigniter for a while on many projects and it had been very useful as it is non-intrusive. Its very small footprint also allows for the extremely good performance on page loads. However, these projects were simply using just the CI core and not implementing any plugins. Some base classes have been extended, but purely specifically for the individual project so not causing any conflict with other code.
Recently, I started building a startup project using CI and would like to employ more plugins do speed up development. Pleasantly surprised, I found that CI had implemented Sparks for searching and installing plugins to CI. Great right! So I implemented an ORM called DataMapper and it was brilliant.
Here comes the reality check. After upgrading from CI 2.0.2 to 2.0.3, everything broke. Why? Because CI changed a lot of methods within its core classes from public to protected. That of course is not actually a bad thing as it was in fact incorrectly implemented before allowing a developer to mess with core functionality too much. However, through researching into these issues, I came to a huge realization that I missed about CI before. CI only allows plugins and developers to modify core classes by extending them into MY_core_class.php. If multiple plugins need to extended the same class, even if they need to overload different methods, it requires some code merging by the developer. If the plugins need to overload the same method in the same core class, that becomes a huge undertaking for the developer to understand what each plugin is trying to do and write merged code that works for both in the same overloaded method.
After that realization, I have determined that CI is fine for applications that are going to use mainly the core classes. If you intend to implement plugins, be very careful understanding what core classes each one will extend. Choose wisely. If those requirements cannot be met, look for another framework.
Code debt accumulating interest
I get into this trap a little too often. I know there is some code that is not written correctly but for the sake of moving along, I ignore it temporarily with the intention of going back to refactor later on. Of course it is not something that is broken, but just poor convention and naming type of stuff. As I build more on top of that, whatever mess that was there before begins to infiltrate into new code through the use of those classes. If I extend upon them, it opens even a greater can of worms.
A friend had talked about code debt before and it speaks so true to these situations. Code debt will incur interest over time if not paid up. The longer you wait, the more expensive the payoff becomes. So just how I like to be financially debt-free, I should strive for code debt-free also.
Running stored procedures on MSSQL via any language on Linux
If you need to run store procedures on Microsoft SQL Server on perl, php, ruby, etc., you need to configure /etc/freetds/freetds.conf with the server connection information. Specifically, specify the tds version to be 8.0. Something like the following.
/etc/freetds/freetds.conf
[Server80]
host = domain.com
port = 1433
tds version = 8.0
Connection to the server via php would look like this.
$link = mssql_connect("Server80", "user", "pass");
Sphinx Search default limit is 20
When using the sphinx api, you must use SetLimts if you want more than 20 records. Currently, it is not documented on the sphinx api doc.
Google maps info window size problem with images
One strange thing when using Google Maps API with pictures in the info window is that sometimes the window is not tall enough to enclose all the content. It overflows the white info window background. The problems is because Google maps API tries to calculate the height of all the content while the photos are being pulled by other http requests. They are asynchronous and the photos might take longer to load than it takes for Google Maps API to determine what the height of the info window should be. It has been said that setting the height of the element would give Gmaps a hint as to how tall the photos might be and adjust accordingly. So doing something like the following would help.
<img src="pic.jpg" height="80" />
Also, if you are using any sort of table or div containers for the image, it would also help to specify the height of the container element to make sure Gmaps knows to account for it.
<table>
<tr height="80">
<td>
<img src="pic.jpg" height="80" />
</td>
</tr>
</table>
Hope that helps you solve this little problem.
asp.net formview problem updating data
Very strange behavior with formviews on asp.net. For some reason, if I declare the SqlDataSource on the page source but then do the binding of the SqlDataSource to the formview in code behind, no error are shown but the data does NOT get updated on edit.
So instead of doing this in code behind
summary.DataSourceID = "summaryDS";
summary.DataBind();
I need to do this on the page
<asp :FormView ID="summary"
runat="server"
DataSourceID="summaryDS">
Develop and Debug – Android On A G1
This is a great way to debug your Android app on a G1 or any Android driven device via USB. It is a much better way to go than the emulator if you have the resources.
Update Delayed on Mysql and PHP
Wouldn't it be nice if we could use UPDATE DELAYED in mysql just like we do use INSERT DELAYED? Unfortunately, the work around mysql created for this is to insert a record into the events table in order to separate UPDATE statement into another thread. There is a large overhead to inserting to then execute an update.
If you are using PHP with mysql, there is another work around. PHP has a function called, register_shutdown_function, which will execute a function during the shutdown of processing a script file. So if we add an UPDATE LOW_PRIORITY sql statement wrapped in a function that is passed to register_shutdown_function, we can allow the user to receive the page without delay while the UPDATE statement waits until all locks on the table has been release before proceeding.
function update_delayed()
{
$sql = "UPDATE LOW_PRIORITY table_name SET col1 = 'something'";
mysql_query($sql, $conn);
}
register_shutdown_function('update_delayed');
I wonder if there are even better ways to handle this problem.