Showing posts with label Vanilla Forum. Show all posts
Showing posts with label Vanilla Forum. Show all posts

Tuesday, May 08, 2012

When your 'mktime' is slow as shit

While working on Vanilla Forum, I realized that dashboard was taking around 3 seconds to load on LAN. When looked further using Xdebug and cachegrind log, I realized that a method called "UnixTimestamp" (in Framework.Functions.php) was calling a stupid method called "mktime". What it does is just return the timestamp value (elapsed int value from a stupid start date of C which will create problem 2030). Not sure why on the earth this should happen, but this method is utter slow. So slow that when I wrote got the UTC time from my MySQL server (of local machine), it was 3 time fast.

Conclusion:
If your mktime is slow, throw that shit out and use stupider but faster method.. i.e. tell MySQL to do it for you. Here is what I wrote:

 
  $query = sprintf("SELECT UNIX_TIMESTAMP('%s') as UTS",
     mysql_real_escape_string($DateTime));
  $result = mysql_query($query);
  if($row = mysql_fetch_assoc($result)) {
     return $row['UTS'];
  }
May PHP god have mercy on you! Happy Coding!

Monday, June 21, 2010

Solve “You are not allowed to upload ‘FileName’. the requested file type: 'FileType’” problem on Vanilla Forum 1.x

Issue:

You get this exception when you try to upload any file in your Vanilla Forum (Version 1) using any Attachment extension :
You are not allowed to upload ‘FileName’. the requested file type: 'FileType’

Resolution 1:

Add specified type as allowed type. Steps to do so follow here:

  1. Note the 'FileType’ in the error message.
  2. Go to extensions\Attachments\default.php file in your Vanilla forum’s directory.
  3. Add appropriate entry in Context->Configuration['ATTACHMENTS_ALLOWED_FILETYPES'] list.
  4. Note that it’s also important that you give correct extensions for the mime type you are allowing as both, 'FilteType’ (i.e. mime type) and file extensions are corss checked in Framework code of vanilla forum.
  5. Save the file and test.

Resolution 2:

Remove check for allowed types. Note that this is not very safe for public forum but it’s ‘ok’ for internal forum with known and responsible user. Steps to do so follow here:

  1. Go to “library\Framework\Framework.Class.Uploader.php”  file.
  2. Find this line of code “if (!array_key_exists($FileType, $this->AllowedFileTypes))”  and comment this ‘if’ and ‘else’ of it. Yes you need to comment if AND else.
  3. Save the file and test.