Topics

Solutions

Easy solutions and ideas found after long googling or hard coding

Keywords Highlighter

Simple keyword highlighter for your google searches. Enabling the extension will automatically highlight all keywords with different colors on all pages.

Screen Shot 2016-02-10 at 3.30.26 AM

Download from Chrome Store
Check Source Code

Fix W3 Total Cache W3_Plugin_TotalCache::ob_callback() expected to be a reference

Around a year ago I was playing with W3 Total Cache plugin on HHVM while I got an annoying warning

Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /wp-includes/functions.php on line 3269

The funny part is that one of the functions was passing by reference which I still could not find the reason for it, maybe it was a limitation in PHP 4.3. Removing one character “&” fixed the issue so I submitted a pull request to the author although the repository currently does not accept pull request. Later on as PHP 7.0 was released, the issue started to show on PHP as well which brought more attention to this small fix. The users comments included anger such as user @kmob2 who said

this is becoming a running gag

Even more user @pratham2003 proposed a one line bash command to solve the problem

sed -i.bak 's/function ob_callback(&/function ob_callback(/g' /path/to/public_html/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php

I hope that the developers will finally listen to the users and fix it soon!

AWS Client v1.2

AWS Client is an open source JavaFX GUI desktop application for Amazon EC2, providing monitoring and filtering controls over your EC2 server instances in different regions. It also allows you to easily interact with your instances via your SSH client. More functionality will be added soon so follow my blog and watch AWS Client code on GitHub

Screen Shot 2016-01-28 at 2.01.59 AM



Download for Mac OSX and Windows
Source Code

Replacing URLs in HTML and JS with mod_proxy on apache 2.2

Simple way to replace URLs for proxied websites using mod filter and substitute

<VirtualHost *:80 >
ProxyPreserveHost On
ServerName proxy-test.example.com
FilterDeclare MYFILTER
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $text/
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/xml
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/json
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/javascript
<Location />
#disable gzip
RequestHeader unset Accept-Encoding
FilterChain MYFILTER
Substitute "s!(images|static|test).example.com!proxy-$1.example.com!i"
</Location>
ProxyPass / http://test.example.com/
ProxyPassReverse / http://test.example.com/
</VirtualHost >
Modify on Gist

Limiting connections and requests to WordPress with Nginx

WordPress could get very slow if used without limitations or protection. I wrote about Nginx HttpLimitReqModule and HttpLimitZoneModule a while ago which could be customised as following to protect WordPress blog.

http{
    ....

    geo $limited {
        default 1;
        127.0.0.1 0;
    }

    map $limited $limit {
        1        $binary_remote_addr;
        0        "";
    }

    #http://wiki.nginx.org/HttpLimitConnModule
    #concurrent connections limited to 200
    limit_conn_zone  $limit  zone=concurrent:10m;
    limit_conn_log_level warn;
    limit_conn  concurrent  200;


    #http://wiki.nginx.org/HttpLimitReqModule
    #PHP serve zone to limit requests to 50 per second
    limit_req_zone $limit zone=php:10m rate=50r/s;

    #limit searches to 100 request per minute
    limit_req_zone $limit zone=search:10m rate=100r/m;

    #login zone to limit login request to 1 request per second
    limit_req_zone $limit zone=login:10m rate=1r/s;

    limit_req_log_level  warn;

    server {
        .....

        error_page 449 = @search;
        #limit search requests
        if ( $arg_s ){
            return 449;
        }
        location @search {
            limit_req   zone=search nodelay;
            rewrite / /index.php?$args last;
            include /etc/nginx/fastcgi_params;
        }

        location = /wp-login.php {
            limit_req  zone=login nodelay;
            include /etc/nginx/fastcgi_params;
        }

        location ~ \.php$ {
            limit_req zone=php burst=50;
            include /etc/nginx/fastcgi_params;
        }

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close