If you need to test a code in browser – try http://ideone.com/
Entry found on http://alouche.net/blog/2009/11/24/ideone-compiler-pastebin/
Dec 22
Posted by admin in php | No Comments
If you need to test a code in browser – try http://ideone.com/
Entry found on http://alouche.net/blog/2009/11/24/ideone-compiler-pastebin/
Tags: code in browser, code testing, pastebin, php
Geotagging script (http://themeforest.net/user/php4ucouk)
Script converts visitor’s ip adress into :
and BONUS
Data is provided to you, so you can use it (display it, store in db or do whatever you need)
Tags: geotagging, php, user stats, visitors live stats
I’ve installed fresh version of Ubuntu 9.04 with Lamp, but I couldn’t send emails outside.
Problem was SMTP auth of outgoing server, spending time found http://dbaron.org/linux/sendmail who made my day. Thanks
Change your SF_APP/web/index.php file to be:
$timer = sfTimerManager::getTimer('myTimer'); sfContext::getInstance()->getController()->dispatch(); $timer->addTime(); $elapsedTime = $timer->getElapsedTime(); $fullRealUri = str_replace( sfContext::getInstance()->getRequest()->getUriPrefix(), "", sfContext::getInstance()->getRequest()->getUri()); file_put_contents('/tmp/time.log',date('Y-m-d H:i:s')."|$fullRealUri|$elapsedTime\n\r",FILE_APPEND); |
Tags: log, optimisation, Symfony, time
Install SSh2 extension for PHP, then you can use class below:
<?php /** * Class to deal with sFTP connections * to use install http://php.oregonstate.edu/manual/en/ssh2.installation.php * */ class SFTPConnection { private $connection; private $sftp; public function __construct($host, $port=22) { if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } $this->connection = ssh2_connect($host, $port); if (! $this->connection) throw new Exception("Could not connect to $host on port $port."); } public function login($username, $password) { if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } if (! @ssh2_auth_password($this->connection, $username, $password)) throw new Exception("Could not authenticate with username $username " . "and password $password."); $this->sftp = @ssh2_sftp($this->connection); if (! $this->sftp) throw new Exception("Could not initialize SFTP subsystem."); } public function uploadFile($local_file, $remote_file) { if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } $sftp = $this->sftp; $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'w'); if (! $stream) throw new Exception("Could not open file: $remote_file"); $data_to_send = @file_get_contents($local_file); if ($data_to_send === false) throw new Exception("Could not open local file: $local_file."); if (@fwrite($stream, $data_to_send) === false) throw new Exception("Could not send data from file: $local_file."); @fclose($stream); } function scanFilesystem($remote_file) { if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } $sftp = $this->sftp; $dir = "ssh2.sftp://$sftp$remote_file"; $tempArray = array(); $handle = opendir($dir); // List all the files while (false !== ($file = readdir($handle))) { if (substr("$file", 0, 1) != "."){ if(is_dir($file)){ // $tempArray[$file] = $this->scanFilesystem("$dir/$file"); } else { $tempArray[]=$file; } } } closedir($handle); return $tempArray; } public function receiveFile($remote_file, $local_file) { if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } $sftp = $this->sftp; $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'r'); if (! $stream) throw new Exception("Could not open file: $remote_file"); $contents = fread($stream, filesize("ssh2.sftp://$sftp$remote_file")); file_put_contents ($local_file, $contents); @fclose($stream); } public function deleteFile($remote_file){ if (!extension_loaded('ssh2')) { throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini."); } $sftp = $this->sftp; unlink("ssh2.sftp://$sftp$remote_file"); } } ?> |
Today I wanted to create some progress indicator PHP command line, after minute googling I found http://forums.devshed.com/php-development-5/php-cli-progress-indicator-151590.html
After slight change:
function progressBar($current, $total, $label) { $percent = round($current / $total * 100); if ($current == 0) { if ($label == "") echo "Progress: \n"; else if ($label != "none") echo $label."\n"; echo "|"; } else { for ($place = 20; $place &gt;= 0; $place--) { echo "\010"; } } for ($place = 0; $place &lt; 15; $place++) { if ($place &lt;= ($percent*0.15)) echo "*"; else echo " "; } echo "| ".sprintf('%3.0f',$percent)."%"; if ($current == $total) { echo "\n"; } } |
Tags: cli, php, progress bar
You are currently browsing the archives for the php category.
![]() | Loading Feed... |
![]() | Loading Feed... |
![]() | Loading Feed... |
![]() | Loading Feed... |
Arclite theme by digitalnature | powered by WordPress