Troubleshooting SugarCRM – Extraneous characters

bsoremsugar —  March 27, 2010 — 5 Comments
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /media/truecrypt1/htdocs/……/SugarEnt-Full-5.5.1/include/entryPoint.php:1) in /media/truecrypt1/htdocs/……/SugarEnt-Full-5.5.1/include/MVC/SugarApplication.php on line 410

-
How many times have we seen an error like this at one time or another?  Or many you just see add text in the upper left hand corner of the screen.  Sometimes it is easy to find and sometimes it becomes an out of control hunt through SugarCRM’s thousands of files.

What causes error like this are extraneous characters outside of the PHP beginning and end script tags.  So somewhere a file has an extra space (or any other character) at the very beginning or end of the script.  Something like this

hi<?php

I have seen people do things like this for debugging and then forget to remove it and a week later when they get complaints from users, the hunt is on because they completely forgot what files they edited.  Now sometimes the unwanted text is in the file referenced in the error, in this case entryPoint.php, but that is not always the case.  If you have deep includes or output buffer capturing then the characters could be anywhere.  So if it is not  in that file this is what I do.

Get a list of recently edited files

In linux you would just run a command like

find . -mtime -3

and that would give you all the files edited in the last 3 days.  I am sure there is a pretty "point and click" way to do the same thing in windows, you'll have to Google that if your stuck pointing and clicking on your server.  From that list you might be able to jog your memory and at worst you will have a short list of files to start with.  But lets say that the file was edited a while ago or you have done alot of work since then and this list of files is useless.   When then we will need a more complicated script to actually look at each file and flag those that have characters outside the script tags.  Something like this.

It may not be pretty but it works.  This will produce two lists of files, one listing all the files that have something before the script tag (<?php) and one listing all files after the script tag (?>).  You would just run it with the “php -f” command from inside your SugarCRM directory.  Something like this.

ken@ken-laptop:/opt/lampp/htdocs/........./SugarEnt-Full-5.5.1$ php -f ../../FindWhiteSpace.php

Files with issue at the beginning of the file
---------------------------------------
./cache/themes/Sugar/pathCache.php
-First Character: "a" (97)
./cache/upload/upgrades/module/Test_5512010_03_23_160222-manifest.php
-First Character: "" (32)
./cache/upload/upgrades/temp/2rDpev/manifest.php
-First Character: "" (32)
./custom/modulebuilder/builds/Test_551/manifest.php
-First Character: "" (32)
./include/SugarObjects/templates/issue/language/application/en_us.lang.php
-First Character: "" (32)
./include/domit_rss/example_domit_rss_lite.php
-First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60)
./include/domit_rss/testing_domitrss.php
-First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60)
./include/entryPoint.php
-First Character: "1" (49)
./include/phpmailer/language/phpmailer.lang-ja.php
-First Character: "" (0)
./install/language/pt_br.lang.php
-First Character: "�" (239)
./modules/Administration/undoupdateclass.php
-First Character: "" (10)
./modules/Campaigns/Subscriptions.php
-First Character: "" (32)
./modules/Home/PopupSugar.php
-First Character: "&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;" (60)
./modules/MailMerge/Step2.php
-First Character: "" (32)

Files with issue at the end of the file
---------------------------------------
./cache/smarty/templates_c/%%03^03B^03B20820%%singletabmenu.tpl.php
./cache/smarty/templates_c/%%D4^D4D^D4D49BFB%%PackageForm.tpl.php
./cache/upload/upgrades/temp/2rDpev/SugarModules/modules/KAB_Test551/metadata/popupdefs.php
./custom/modulebuilder/builds/Test_551/SugarModules/modules/KAB_Test551/metadata/popupdefs.php
./custom/modulebuilder/packages/Test_551/modules/Test551/metadata/popupdefs.php
./include/Popups/Popup_picker.php
./include/SugarFields/Parsers/DetailViewMetaParser.php
./include/SugarFields/Parsers/SearchFormMetaParser.php
./include/SugarObjects/templates/basic/metadata/popupdefs.php
./include/SugarObjects/templates/company/metadata/editviewdefs.php
./include/SugarObjects/templates/company/metadata/popupdefs.php
./include/SugarObjects/templates/company/metadata/searchdefs.php
./include/SugarObjects/templates/file/language/en_us.lang.php
./include/SugarObjects/templates/file/metadata/SearchFields.php
./include/SugarObjects/templates/file/metadata/listviewdefs.php
./include/SugarObjects/templates/file/metadata/searchdefs.php

Again, there will be alot of false positives on this list (I submitted a bug to the engineers to see if we can get this list shortened up a bit) but it is a great start.  From thousands of files down to a few dozen.

5 responses to Troubleshooting SugarCRM – Extraneous characters

  1. 

    Cheers, I have also encounted this issue when the doc type is not corrent with the file type and the browser chucks out some weird characters before the headers are sent. A very annoying problem.

  2. 

    Cheers, I have also encounted this issue when the doc type is not corrent with the file type and the browser chucks out some weird characters before the headers are sent. A very annoying problem.

  3. 

    Could you explain what you mean, maybe I can modify this program to find those too. I sort of understand what you are saying but not sure it applies to SugarCRM.

  4. 

    Could you explain what you mean, maybe I can modify this program to find those too. I sort of understand what you are saying but not sure it applies to SugarCRM.

  5. 

    I have SugarCRM 6.0.1 and fromtime to timewhen I try to enter a lead or account the page that opens in blank and trying to re-enter doesn’t help. Have you see this porblem? I’m looking for a fix. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s