Archive for September, 2012

Export large database to file without mysqldump, low memory footprint

I am exporting a large database and wanted to know the best way to make it have a low memory footprint.

I realize that I must do this in cycles that have a time limit and use low memory, fetching say 100 rows at a time and saving the information to the file then redirect to start a new cycle starting from where it finished on the previous cycle.

I am wondering whats the best way buffer the data to file and not run out of memory, at present the script gets all data as a string then saves to file when it has finished getting all rows from the database. Some times it runs out of memory, hence the need to fix.

Do I use fwrite() on the data fetched from the database instead of putting into a var or use a temp file? If I use a temp file when do I merge/rename into the backup file?

Basically what is the best way for the script to export the database data into a file without getting the error “Fatal Error: PHP Allowed Memory Size Exhausted”?

Code Here

Examples welcome

canvas toDataUrl() how to get base64 result into and out a msql blob field

Can someone help me

I want to store the canvas image into a blob field

on the serverside I receive a base64 encoded string from toDataUrl()

  • What do I have to do to get it into a blob field

  • And how do I display it again in an img tag

what code do I need to use?
the mysql page is not very clear


PHP Swift mailer: Failed to authenticate on SMTP using 2 possible authenticators

When I send an email with the PHP Swift mailer to this server: like this:

/ Load transport
$this->transport =

// Load mailer
$this->mailer = Swift_Mailer::newInstance($this->transport);

// Initialize message
$this->message = Swift_Message::newInstance();

// From

// .. Set message etc.

// Send

I get a strange error back

Failed to authenticate on SMTP server with username “” using 2 possible authenticators

I know for sure that the login info is correct. What can be the problem?

Reasons for using a javascript MVC framework over PHP Yii?

I’m starting to write a web site from scratch using PHP Yii maintained by me only. My main concern is maintainability.
What are the reasons for using a javascript MVC framework (like AngularJs or EmberJs or KnockoutJs) over PHP Yii?

I haven’t tried Yii MVC or any of those JS frameworks yet.

Struggling to display blob image with php

I am building a simple website, I want to allow the users to upload and change their avatars. At present I have been able to upload images to a mysql database, stored as blobs with the code as follows:

//connected to DB, userID fetched

$image = $FILES['fileToUpload']['tmp_name'];
$fp = fopen($image, 'r');
$content = fread($fp, filesize($image));
$content = addslashes($content);

$sql = "UPDATE tbUsers SET profileImage = '".$content."' WHERE userID = ".userID;
$result = mysql_query($sql) or die (mysql_error());

When I download the files from phpmyadmin after upload they are saved as .bin files, but can be viewed normally. I’m not sure if this is correct or not.
My code to display the images is as follows:


<?php echo '<img src ="showPic.php?q='.$_SESSION['profile'].'"/>'; ?>
//ID of the user profile sent


if (!empty($_GET['profile']) && is_numeric($_GET['profile']))
  $con = mysql_connect("localhost", "root", "");
  $sql = "SELECT profileImage FROM tbUsers WHERE userID = ". $_GET['profile'];
  $result = mysql_query($sql) or die (mysql_error());

  header('Content-type: image/jpeg');
  $row = mysql_fetch_object($result);
  echo $row['image_data'];

I am unsure if I am attempting to display the image in the correct way, any help (corrections/alternative solutions) would be greatly appreciated :)

In my Apache Server I can’t seem to be getting mod_rewrite to work for some reason

In Apache I have the following setup in the config file:

  LoadModule rewrite_module modules/

  DocumentRoot "C:/mywebdev/apache/www"
  RewriteEngine On
  Include conf/extra/httpd-vhosts.conf

  <Directory "C:/mywebdev/apache/www">
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from All

I have the following in my vhosts config

  <Directory "C:/mywebdev/apache/www/test">
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from All

  NameVirtualHost *:80

  <VirtualHost *:80>
  DocumentRoot C:/mywebdev/apache/www/test
  ServerAlias *
  ServerAdmin webmaster@dummy-host.localhost
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/library/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]

I checked to see if was in the modules folder and it is there. The module is not working for this or any other mod_rewrite rule I’ve attempted to use. Thanks in advance for any assitance.

Update as to show how other mod_rewrite rules not being applied. I’m trying to use minify. Link- -This is what I get from the index file within min folder which is in vhost root:
Note: Your webserver does not seem to support mod_rewrite (used in /min/.htaccess). Below is what is in the .htaccess file:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    # You may need RewriteBase on some servers
    #RewriteBase /min
    #rewrite URLs like "/min/f=..." to "/min/?f=..."
    RewriteRule ^([bfg]=.*)  index.php?$1 [L,NE]
    <IfModule mod_env.c>
    #In case AddOutputFilterByType has been added
    SetEnv no-gzip

Access log reports: - - [30/Sep/2012:13:33:22 -0400] "GET /min/builder/ HTTP/1.1" 304 - - - [30/Sep/2012:13:33:23 -0400] "GET /min/?f=min/builder/_index.js HTTP/1.1" 304 - - - [30/Sep/2012:13:33:23 -0400] "GET /min/builder/ocCheck.php?1349026403311 HTTP/1.1" 200 21 - - [30/Sep/2012:13:33:23 -0400] "GET /min/?f=min/builder/bm.js HTTP/1.1" 304 - - - [30/Sep/2012:13:33:23 -0400] "GET /min/?f=min/builder/bm2.js HTTP/1.1" 304 - - - [30/Sep/2012:13:33:23 -0400] "GET /min/f=min/builder/rewriteTest.js&1349026403332 HTTP/1.1" 404 - - - [30/Sep/2012:13:33:24 -0400] "GET /favicon.ico HTTP/1.1" 404 - - - [30/Sep/2012:13:33:24 -0400] "GET /min/builder/ocCheck.php?1349026403311&hello=1 HTTP/1.1" 200 8

Error log reports nothing at all. It does if I have an error but not for this which is not giving off an error. This just shows clearly that it is not working. No errors when I do restart in Apache. Again thanks for any assistance.

Understandin PHP 404 redirection related to invalid get request

Ok, am using traditional php, no frameworks, nothing, I am using simple procedural way, now my question is I was searching for a while but am not getting an answer to my question, I am not using .htaccess files as of now, but I really need to understand how 404 error works? I am having a website, where I show post’s related to category, say category=php, so I pass this as a get request

$_GET['category'] == 'php';

Now currently what am doing is something like this :

$pocategory = $_GET['category'];

if($pocategory == 'php' || $pocategory == 'javascript') {
//Then show related posts
} else {

I mean I just want php and javascript as valid request’s value, rest I want to redirect to 404 but am not understanding how to do it so I did this way, what if am having more than 50 categories? I cant list them all in this if condition, Inshort how to detect whether the given get request value is invalid or not..

Any help will be much appreciated.

PHP Equivalent to Authorized ASP.NET WebMethod (AJAX)?

It’s rare, but I have to pay MS a compliment: the ASP.NET WebMethod (AJAX) authorization is a dream, regarding my desire for security and laziness.

Encosia’s ASP.NET page methods are only as secure as you make them absolutely fits those needs. ASP.NET is actually workable for me now. Free at last! (From the noble but disastrous AJAXControlToolkit).

Anyways, the problem is, that’s for work. I’m not buying the MS architecture when LAMP’s out there for free. I’m new to AJAX, and I can’t seem to find a clear answer on how to authorize AJAX calls to PHP in the same way as Encosia above.

Can anyone suggest the PHP equivalent of what Encosia does in the link above?

Thanks in advance!

More Details

OK, let me be more specific. Encosia’s solution above gives 401 denied to anyone not logged in trying to access a webmethod. Neat, clean, easy. Before, I tried to user session data to give access, but it, unknowingly to me, forced synchronous mode. Nono.

I need both, for my site. I need to be able to give 401 denieds on certain pages if a user isn’t logged in. I need to be able to allow anyone to call other phps via ajax regardless of login.

Get data from a facebook page wall or group wall for use on personal website

I want to connect to public facebook page or group and list all entries from the wall on a personal website. I will use PHP on my server so that would be the best solution for me. Or javascript.

Could anyone explain or perhaps give a working code on how to do this? Or just all steps nessesary for making this?

If its possible to handle information about person, date, description … for each post, that would be great! So my layout could be customized.

Thanks for helping me out here!

DirectoryIterator to RecursiveDirectoryIterator

I’m trying to create a simple file browser which I can do with DirectoryIterator, but that doesn’t tell me how many files are in each directory.

How can I convert the example below to use RecursiveDirectoryIterator, so I can output the total number of files within each linked directory?

define('ROOT', '/path/to/somewhere');
$cwd = ROOT;

if(isset($_GET['path']) && is_dir($cwd.$_GET['path'])) {
    $cwd .= $_GET['path'];

foreach(new DirectoryIterator($cwd) as $file) {
    if($file->isDot()) {
    if($file->isDir()) {
        $path = str_replace(ROOT, '', $file->getPathname());
        echo "<a href=\"{$_SERVER['PHP_SELF']}?path=$path\">{$file->getFilename()}</a>";
    } else {
        echo $file->getFilename();
    echo '<br />';

Desired Result:

Folder1 (3 files)
FOlder2 (1 file)
Folder3 (14 files)

Actual Result:

Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.