PHP and 2GB Size Files

Today, I was trying to open a 2.5 GB file in PHP. PHP was unable to open the file on my 32 bit machine, but it worked great on my 64 bit machine. Running the script on my 64 bit machine wasn’t an option, so it was time to do some digging into the problem.

I know that there are a lot of memory issues when crossing the 2 GB barrier due to design limitations with 32 bit systems. After some digging, I found that you need to enable what a lot of people call “Large File Support” or LFS. At first, I only saw references to it as LFS, so I thought…. Linux From Scratch, but I guess I was wrong.

To add the Large File System support, add the following to your configure line.

CFLAGS=”-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64″

In my case, it looks like…

CFLAGS=”-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64″ ./configure
–with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/mysql
–with-libxml-dir=/usr/local/

I found the answer on PHP.net right here.

-Kim

Kohana MySQL Memory Leak

So, I’ve been building a Kohana CGI script to import over 2 million records of data into my MySQL database. After testing, I started the app. After a few minutes, the app ended with an out of memory error.

Well, this error was specifically related to Kohana.(There were others…) It turns out that the Kohana database library was using up all of the memory.

To fix your app, just adjust the “‘benchmark’ => TRUE,” from TRUE to FALSE and you won’t run out of memory because of the database.

-Kim

Apache make infinite loop

So I was building Apache to today, and it seemed to be taking a long time. The first thing to come to mind was the bad memory I had earlier today. A long story short, the time on my computer was set to March 14, 2003. Once I updated the time, everything worked great.

Here is what part of the infinite loop looked like…

checking for getpagesize… yes
checking for working mmap… yes
checking for memmove… yes
checking for bcopy… yes
configure: creating ./config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= /bin/sh config.status
config.status: creating Makefile
config.status: WARNING: ‘Makefile.in’ seems to ignore the –datarootdir setting
make[3]: Leaving directory `/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat’
make[3]: Entering directory `/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat’
make[3]: Warning: File `Makefile.in’ has modification time 2e+08 s in the future
running CONFIG_SHELL=/bin/sh /bin/sh /home/kim/httpd-2.2.14/srclib/apr-util/xml/expat/configure –disable-option-checking –enable-so –enable-mods-shared=all –srcdir=/home/kim/httpd-2.2.14/srclib/apr-util –with-apr=../apr –libdir=${prefix}/lib –bindir=${prefix}/bin –cache-file=/dev/null –srcdir=/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat –prefix=/usr/local/apache2 –exec-prefix=/usr/local/apache2 –libdir=/usr/local/apache2/lib –includedir=/usr/local/apache2/include –bindir=/usr/local/apache2/bin –no-create –no-recursion
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking target system type… i686-pc-linux-gnu
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking for a sed that does not truncate output… /bin/sed
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for ld used by gcc… /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld… yes
checking for /usr/bin/ld option to reload object files… -r
checking for BSD-compatible nm… /usr/bin/nm -B
checking whether ln -s works… yes
checking how to recognize dependent libraries… pass_all
checking how to run the C preprocessor… gcc -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking dlfcn.h usability… yes
checking dlfcn.h presence… yes
checking for dlfcn.h… yes
checking for g++… g++
checking whether we are using the GNU C++ compiler… yes
checking whether g++ accepts -g… yes
checking how to run the C++ preprocessor… g++ -E
checking for g77… no
checking for xlf… no
checking for f77… no
checking for frt… no
checking for pgf77… no
checking for cf77… no
checking for fort77… no
checking for fl32… no
checking for af77… no
checking for xlf90… no
checking for f90… no
checking for pgf90… no
checking for pghpf… no
checking for epcf90… no
checking for gfortran… no
checking for g95… no
checking for xlf95… no
checking for f95… no
checking for fort… no
checking for ifort… no
checking for ifc… no
checking for efc… no
checking for pgf95… no
checking for lf95… no
checking for ftn… no
checking whether we are using the GNU Fortran 77 compiler… no
checking whether accepts -g… no
checking the maximum length of command line arguments… 98304
checking command to parse /usr/bin/nm -B output from gcc object… ok
checking for objdir… .libs
checking for ar… ar
checking for ranlib… ranlib
checking for strip… strip
checking if gcc supports -fno-rtti -fno-exceptions… no
checking for gcc option to produce PIC… -fPIC
checking if gcc PIC flag -fPIC works… yes
checking if gcc static flag -static works… yes
checking if gcc supports -c -o file.o… yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries… yes
checking whether -lc should be explicitly linked in… no
checking dynamic linker characteristics… GNU/Linux ld.so
checking how to hardcode library paths into programs… immediate
checking whether stripping libraries is possible… yes
checking if libtool supports shared libraries… yes
checking whether to build shared libraries… yes
checking whether to build static libraries… yes
configure: creating libtool
appending configuration tag “CXX” to libtool
checking for ld used by g++… /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld… yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries… yes
checking for g++ option to produce PIC… -fPIC
checking if g++ PIC flag -fPIC works… yes
checking if g++ static flag -static works… yes
checking if g++ supports -c -o file.o… yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries… yes
checking dynamic linker characteristics… GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs… immediate
appending configuration tag “F77″ to libtool
checking for gcc… (cached) gcc
checking whether we are using the GNU C compiler… (cached) yes
checking whether gcc accepts -g… (cached) yes
checking for gcc option to accept ISO C89… (cached) none needed
checking for a BSD-compatible install… /usr/bin/install -c
checking for ANSI C header files… (cached) yes
checking fcntl.h usability… yes
checking fcntl.h presence… yes
checking for fcntl.h… yes
checking for unistd.h… (cached) yes
checking for string.h… (cached) yes
checking whether byte ordering is bigendian… no
checking for an ANSI C-conforming const… yes
checking for off_t… yes
checking for size_t… yes
checking for working memcmp… yes
checking for stdlib.h… (cached) yes
checking for unistd.h… (cached) yes
checking for getpagesize… yes
checking for working mmap… yes
checking for memmove… yes
checking for bcopy… yes
configure: creating ./config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= /bin/sh config.status
config.status: creating Makefile
config.status: WARNING: ‘Makefile.in’ seems to ignore the –datarootdir setting
make[3]: Leaving directory `/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat’
make[3]: Entering directory `/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat’
make[3]: Warning: File `Makefile.in’ has modification time 2e+08 s in the future
running CONFIG_SHELL=/bin/sh /bin/sh /home/kim/httpd-2.2.14/srclib/apr-util/xml/expat/configure –disable-option-checking –enable-so –enable-mods-shared=all –srcdir=/home/kim/httpd-2.2.14/srclib/apr-util –with-apr=../apr –libdir=${prefix}/lib –bindir=${prefix}/bin –cache-file=/dev/null –srcdir=/home/kim/httpd-2.2.14/srclib/apr-util/xml/expat –prefix=/usr/local/apache2 –exec-prefix=/usr/local/apache2 –libdir=/usr/local/apache2/lib –includedir=/usr/local/apache2/include –bindir=/usr/local/apache2/bin –no-create –no-recursion
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking target system type… i686-pc-linux-gnu
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking for a sed that does not truncate output… /bin/sed
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for ld used by gcc… /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld… yes
checking for /usr/bin/ld option to reload object files… -r
checking for BSD-compatible nm… /usr/bin/nm -B
checking whether ln -s works… yes
checking how to recognize dependent libraries… pass_all
checking how to run the C preprocessor… gcc -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking dlfcn.h usability… yes
checking dlfcn.h presence… yes
checking for dlfcn.h… yes
checking for g++… g++
checking whether we are using the GNU C++ compiler… yes
checking whether g++ accepts -g… yes
checking how to run the C++ preprocessor… g++ -E
checking for g77… no
checking for xlf… no
checking for f77… no
checking for frt… no
checking for pgf77… no
checking for cf77… no
checking for fort77… no
checking for fl32… no
checking for af77… no
checking for xlf90… no
checking for f90… no
checking for pgf90… no
checking for pghpf… no
checking for epcf90… no
checking for gfortran… no
checking for g95… no
checking for xlf95… no
checking for f95… no
checking for fort… no
checking for ifort… no
checking for ifc… no
checking for efc… no
checking for pgf95… no
checking for lf95… no
checking for ftn… no
checking whether we are using the GNU Fortran 77 compiler… no
checking whether accepts -g… no
checking the maximum length of command line arguments… 98304
checking command to parse /usr/bin/nm -B output from gcc object… ok
checking for objdir… .libs
checking for ar… ar
checking for ranlib… ranlib
checking for strip… strip
checking if gcc supports -fno-rtti -fno-exceptions… no
checking for gcc option to produce PIC… -fPIC
checking if gcc PIC flag -fPIC works… yes
checking if gcc static flag -static works… yes
checking if gcc supports -c -o file.o… yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries… yes
checking whether -lc should be explicitly linked in… no
checking dynamic linker characteristics… GNU/Linux ld.so
checking how to hardcode library paths into programs… immediate
checking whether stripping libraries is possible… yes
checking if libtool supports shared libraries… yes
checking whether to build shared libraries… yes
checking whether to build static libraries… yes
configure: creating libtool
appending configuration tag “CXX” to libtool
checking for ld used by g++… /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld… yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries… yes
checking for g++ option to produce PIC… -fPIC
checking if g++ PIC flag -fPIC works… yes
checking if g++ static flag -static works… yes
checking if g++ supports -c -o file.o… yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries… yes
checking dynamic linker characteristics… GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs… immediate
appending configuration tag “F77″ to libtool
checking for gcc… (cached) gcc
checking whether we are using the GNU C compiler… (cached) yes
checking whether gcc accepts -g… (cached) yes
checking for gcc option to accept ISO C89… (cached) none needed
checking for a BSD-compatible install… /usr/bin/install -c
checking for ANSI C header files… (cached) yes
checking fcntl.h usability… yes
checking fcntl.h presence… yes
checking for fcntl.h… yes
checking for unistd.h… (cached) yes
checking for string.h… (cached) yes
checking whether byte ordering is bigendian… no
checking for an ANSI C-conforming const… yes
checking for off_t… yes
checking for size_t… yes
checking for working memcmp… yes
checking for stdlib.h… (cached) yes
checking for unistd.h… (cached) yes
checking for getpagesize… yes
checking for working mmap… make[3]: *** [config.status] Error 1
make[2]: *** [all-recursive] Interrupt
make[1]: *** [all-recursive] Interrupt
make: *** [all-recursive] Interrupt

The clue was the warning about the make file have a future date.

-Kim

Utah County Ham Radio Nets

I like to participate in Ham Radio, so I figured I it would be nice to share the Ham Radio nets I like to participate in.

ucares.org

The net is on Tuesdays at 9:00 PM Usually on 147.28(Positive Duplex, Tone 141.3). In the past, the net has also been known to be on 147.34(Positive Duplex, Tone 100.0). Every month they have a simplex night where they turn off the repeater and adjust their radios to run off of simplex.

http://erclindon.org/welcome.php

They have a weekly net on Tuesdays at 8:00 PM on 147.020( Positive Duplex, Tone 100)

-Kim

CakePHP mod_rewrite problems

I recently went to launch a website I had put together using CakePHP. Everything look good on my local computer. When I uploaded my content to their server, I saw a rather plain page.

It turns out that I was having a common issue with the mod_rewrite and the pre-built .htaccess files provided by the Cake libraries.

After a bit of research, I was able to correct my issues by adding the RewriteBase to the files. This is the .htaccess in the root directory of the site, as you can see I have added the “RewriteBase /” to the file.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule    ^$   app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

I also had to make this change to the /app/webroot/.htaccess file, but this time the Rewrite base looked like “RewriteBase /app/webroot”

I now have a much firmer understanding of how Apache mod_rewrite works.

-Kim

Access Violations and Kernel Panics

I’ve spent the last few days working on the new computer I purchased, a Foxconn RS233 ITX-Barebone Intel 945GC with an Intel Atom 230.

I installed CentOS 5.3 x86_64 the day the packages arrived. The next day I started to receive the dreaded Kernel Panic and Access violations. At first I was baffled. I did a lot of research and nothing really came up that described my problem. I even updated the firmware for my motherboard.

After a lot of research, I found out the that problem was with the RAM I had purchased. I used Memtest86 to identify the issue. I swapped out the RAM and everything seems to be working well.

Kim

Seti@Home with a PowerPC running Debian

I’ve been trying to get my Seti@Home to work on my old Mac Mini (PowerPC) running Debian. First I got some precompiled binaries(http://www.dotsch.de/boinc/SETI@home%20applications.html) that didn’t work.

Since I am a programmer at heart, I decided that I would get the source code for boinc and seti@home and compile them both.

I first checked out the following code:

svn co http://boinc.berkeley.edu/svn/branches/boinc_core_release_6_2
svn checkout https://setisvn.ssl.berkeley.edu/svn/seti_boinc

With this set of code, seti@home didn’t compile. It turns out that the current release of seti@home(revision 575) depended on values that weren’t in the boinc_core_release_6_2.

I next checked out the following release of boinc, and the example app didn’t work.

svn co http://boinc.berkeley.edu/svn/trunk/boinc

The example app would error out with some of the following information:

[New Thread 805426400 (LWP 15190)]

Program received signal SIGSEGV, Segmentation fault.
0x100073d4 in __gnu_cxx::__exchange_and_add ()
(gdb) backtrace
#0 0x100073d4 in __gnu_cxx::__exchange_and_add ()
#1 0x1001ecec in ~PROXY_INFO (this=0x10046728)
at /usr/lib/gcc/powerpc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:232
#2 0x10015ad4 in ~APP_INIT_DATA (this=0x10045250) at app_ipc.cpp:60
#3 0x10011a58 in __tcf_0 () at boinc_api.cpp:89
#4 0x0fdc31b4 in exit () from /lib/tls/libc.so.6
#5 0x10002378 in main (argc=1, argv=0x7fd46874) at uc2.cpp:168

It turns out the main trunk isn’t functioning at the moment. So if you update your code to a diffent revision we should be okay. After some searching I found the following seems to work.

svn update -r 18818

The next issue that I ran into was that my computer mentions it is a PowerPC, so the source code tries to act like I have Mac OS X or Darwin installed, which I don’t.

After running _autoconf in the seti_boinc folder, change the following in the configure file.

 if test -n "`echo ${target} | grep 'powerpc'`" -o -n "`echo ${target} | grep 'ppc'`" ; then
  PPC_TRUE=
  PPC_FALSE='#'
else
  PPC_TRUE='#'
  PPC_FALSE=
fi

to

 if test -n "`echo ${target} | grep 'powerpc'`" -o -n "`echo ${target} | grep 'ppc'`" ; then
  PPC_TRUE='#'
  PPC_FALSE=
#  PPC_TRUE=
#  PPC_FALSE='#'
else
  PPC_TRUE='#'
  PPC_FALSE=
fi

This is to bypass the auto detection of the OS that seems to break the compile process.

This is everything extra that I needed to do to get Debian PowerPC Seti@Home to work!

Kim

Openoffice DNS Delay

Hello!

I was working with Openoffice and I seemed to be missing some fonts I wanted. So this short blog will maybe help you.

I was trying to install msttcorefonts and I kept getting the following type of errors.

Resolving umn.dl.sourceforge.net… failed: Connection timed out.
–14:13:43– http://switch.dl.sourceforge.net/sourceforge/corefonts/arialb32.exe
=> `./arialb32.exe’

After much searching I finally found the script that was failing. The script is at /usr/sbin/update-ms-fonts

The problem that I have is that my DNS always seems to take forever. So increased the DNS timeout for the wget function call on line 131 to 30 seconds.

I hope this helps someone out!

-Kim

file_get_contents and Godaddy

Godaddy.com and more problems. I was trying to use file_get_contents in PHP to access an HTTPS server. It worked fine for HTTP servers, but once I tried using it ot access an HTTPS server…everything went to …..

After a bunch of research, I finally found the answer on godaddy’s website. It works, but its a pain. I wonder why everyone likes to make things more complicated then they are? Most likely a security feature.

http://help.godaddy.com/article.php?article_id=289&topic_id=435

In case you are board, here are a bunch of links I went to trying to figure out what the problems was.

http://help.godaddy.com/article_list.php?topic_id=435
http://us2.php.net/manual/en/function.curl-exec.php
http://paypaldev.org/topic.asp?TOPIC_ID=13079
http://www.higherpass.com/php/Tutorials/Using-Curl-To-Query-Remote-Servers/
http://us.php.net/curl
http://us3.php.net/ref.info
http://us.php.net/manual/en/function.fread.php
http://us.php.net/fopen
http://us3.php.net/fopen
http://www.thescripts.com/forum/thread706918.html
http://forum.jajah.com/index.php?showtopic=4563
http://www.google.com/search?q=php+file_get_contents+times+out


And it goes on. I needed to get a file in a downloadable form from my website without ever actually existing. Using PHP I managed this trick by following the following webpage’s suggestion.

http://us3.php.net/header

It took me a while to get everything the way I wanted it to…but it works like gold! Anyways, if you are bored….here are a bunch more of the random links for some sort of random entertaining purpose.

http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html
http://us2.php.net/manual/en/function.ircg-html-encode.php
http://www.google.com/search?q=embedded+files+in+html
http://www.alternatiff.com/howtoembed.html
http://www.planetpdf.com/mainpage.asp?webpageid=1682
http://www.ozzu.com/ftopic67590.html
http://forum.java.sun.com/thread.jspa?threadID=5206450&tstart=30
http://www.paulstimesink.com/post/2005/06/29/http_post_with_curl
http://www.google.com/search?q=curl+post+php
http://curl.haxx.se/mail/curlphp-2006-07/0003.html
http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
http://www.phpbuilder.com/columns/ian_gilfillan20050525.php3
http://blog.mypapit.net/2006/02/sending-http-post-with-php-curl.html
http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html
http://www.google.com/search?q=php+file+extension+change
http://radio.userland.com/stories/storyReader$8979
http://us2.php.net/manual/en/features.http-auth.php
http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html#imag
http://www.google.com/search?q=%3CA+href%22+post
http://aujava.wordpress.com/2007/01/17/postable-html-links/
http://www.codingforums.com/showthread.php?t=93227
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-May/003897.html
http://www.w3.org/TR/html4/interact/forms.html
http://www.microsoft.com/technet/isa/2006/http_filtering/9a0d125c-1ee9-4f5c-be28-7d5a185d4c93.mspx?mfr=true
http://www.google.com/
http://support.microsoft.com/kb/208427
http://us.php.net/nl2br