A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.
Read more…
Code Snippets, PHP, Tips
php cli, wordpress, xml rpc
While strolling around I found some bits and pieces which I put together to get a short twitter counter in php.
<?php
ob_start();
$json = file_get_contents("http://twitter.com/statuses/user_timeline/php_trivandrum.json?count=1");
$data = json_decode($json, true);
ob_get_clean();
echo $data[0]['user']['followers_count'];
?>
Nothing more to write now..
Code Snippets, PHP, Tips
php twitter counter, twitter counter
Now a days script driven web applications are getting more and more complicated with background operations and triggered events. Debugging or event tracking is tough once the application is moved into production. Fresh and aspiring programmers are always too cautious to wade into deeper waters, and always go with line by line testing. Almost always in the course of debugging or code optimizations I see a lot of them using file_put_contents or echo to check variables at a particular point of execution.
I always gave the pressure to use a good logging system from the start itself, and to add level based message logging with debug_backtrace wherever needed. The most recent class abstraction for php programmers which is being used in our custom framework is attached to the downloads here. The file logging is being done after serializing, compressing and base64_encoding to keep logs in single lines, and to make sure they dont take up too much of the space.
Read more…
General Articles, PHP, Tips
php command line, php snippets, php wrapper, script logging
Sorry this is nothing related to php, though I wanted to run a cron job or scheduled job at a random time, searching the Internet gave me lots of ideas but I found the apt solution only yesterday.
Read more…
Tips, Uncategorized
cron, shell
This is not much to brag about, still we had a very large dataset as variable dimensional and variable depth, which we wanted to be sent to a custom function using prototype.js. For the data exchange we use JSON, but the varying depth and related tags, made us to do like hell in the javascript templating that we had to find a method to flatten the array in such a way that each of the associative keys would not be mangled.
The final out come is function array_flatten
function array_flatten($p, $ki = ''){
if($ki !== '') $ki .= '-';
$rv = array();
foreach($p as $k => $v){
if(is_array($v))
$rv = array_merge($rv, array_flatten($v, $ki.$k));
else
$rv[$ki . $k] = $v;
}
return $rv;
}
The flattened dataset, helped us to do rendering in less than half the iterations, and the application response was more better after using this.
PHP, Tips
Well this may not be new to you all, but still, when I was on the lookout how I could validate an ip address, all the regular expression techniques either failed on valid addresses or bloated too much. The out come was wrote a piece of code which may help others if this is correct, in its way. Not sure, since most of the addresses which I tested against the other validation methods, and failed or non valid ones which passed were blocked here.
Still I am not the ultimate, if you have better suggestions than the code given here, please do so. Read more…
Code Snippets, Tips
Pseudostreaming is a protocol that can be installed on regular HTTP servers such as Apache, Tomcat, IIS or lighthttpd. It uses a server side script for Flash-to-server communication. The player sends a HTTP request to the server with a start time parameter in the request URL’s query string and the server script responds with the video stream so that its start position corresponds to the requested parameter. This start time parameter is usually named simply start. This same technique is used by the ultra-popular YouTube service which uses lighthttpd servers.
Read more…
Code Snippets, PHP, Tips
flowplayer, pseudostreaming
After about a decade of php and mysql, with just deviating only in the scripting or language area, today morining, I felt like digging into the sqlite3, which a lot of people are referring to, and some good RIA players are paying attention to also. The big names that sqlite website brags about are Adobe, Symbian and Firefox.
Jumping straight into the hands on, though for a prologe or introduction I will brief the respective situation. Kyle Newton of Galaxy WD, a client of Saturn SPL wanted a website to have the famous USAPostalCodes db, but he wanted the system to use pre imported flatfiles, and with about a couple of hours, we could pre import the USAPostalCodes db to the recommended format, though the whole data size was now 170MB. The pages where being generated on the webserver under 1/100 th of a second. Along with php ob_gzhandler was giving a good output. The client was almost satisfied, though he had some other views and that was not about the technology.
Read more…
Code Snippets, Tips
Recently for a project involving travelport xml api integration, we badly needed the soap requests to be gzipped, since the technical support people suggested. Also we were aware of the benefits of using gzEncoded data when transmitting through the Internet. For the same we checked the wid internet searching with all sort of combinations of gzip nusoap request. Speaking from the inner view, we already had developed a handful of classes to abstract the SubmitXML api provided by Galelio Travelport. And frankly were reluctant to trash all the code already written.
At this point, we swam through the whole code of nusoap.php; should say thanks to easyeclipse, and made some minor tweaks here and there. The following was all that was required, though I doubt if this would be a generic solution, this definitely serves our purpose and the versions we used are 0.7.3/Revision: 1.114.
in class soap_transport_http added property gzipRequests (line 2148)
var $gzipRequests = true; // gzip any requests..
in function buildPayload at the top (line 2799)
if($this->gzipRequests){
$data = gzencode($data);
$this->setHeader("Content-Encoding",'gzip');
}
in function sendRequest (about line 2874), just in case the request is using curl
if($this->gzipRequests){
$data = gzencode($data);
}
PHP, Tips
On the article at php|architect, Ligaya Turmelle explains you how to handle Foreign Keys in MySQL so they can serve your whims.
No, foreign keys aren’t from Brazil or Italy or even the US. Though they can be a bit strange to those who do not understand them, have no fear. We are here to teach you how to talk to them so they can serve your whims. So what are foreign keys exactly?
Not to put too fine a point on it, they are what make a relational database “relational.†They are the links between tables that keeps everything connected. They are what allows you to put a customer in one table and their order in another and the products they are ordering in a third table so the database has minimal data redundancies.
She continues with the article with a good example. Read it
Tips, mysql
Recent Comments