phpfox without works without memcache support? - php

is there any way working with Phpfox without memcache service? because i am using hostgator shared server, where as shared server which does not provide any memcache service its only available in dedicated servers only.
I am using Phpfox1.5 is previously hosted in amazon server where mecache service available but its very costly for me so i want to change my site from amazon to hostgator hosting service.
Fatal error: Class 'Memcache' not found in /home/latisse/public_html/spicypeeps.com/include/library/phpfox/cache/storage/memcache.class.php on line 64

Sure, just include a file with this class on top of it:
<?php
// Dummy Memcache for a development environment where Memcache is not installed. Part of mmvc library, https://github.com/kajala/mmvc
// Dependencies: none
//if ( defined('MEMCACHE_COMPRESSED') )
// die( "Memcache seems to be already installed, MemcacheDummy.php should never be included in this case\n" );
define( 'MEMCACHE_COMPRESSED', 1234 ); // dummy value
/**
* Dummy Memcache class for a development environment where Memcache is not installed.
* Note that this class does not do ANYTHING and it is only a convenience for
* the development environment and should never be used in production server.
*/
class Memcache
{
function __construct()
{
}
function connect( $host, $port )
{
assert( is_string($host) );
assert( is_numeric($port) );
return true;
}
function set( $key, $obj, $compressed=false, $expires=0 )
{
assert( is_string($key) );
assert( $compressed === false || $compressed == MEMCACHE_COMPRESSED );
assert( is_numeric($expires) );
return true;
}
function get( $key )
{
assert( is_string($key) || is_array($key) );
return false;
}
}
?>
Note: the code isn't mine, and it is licensed under the BSD license. Original author: link

Related

idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated

I am using codeigniter framework for my site, but in form_validation I am getting error I followed this link in stackoverflow but it didn't work for me
followed link:
idn_to_ascii() in 5.2.17
Issue:
code in codeigniter libraries/form_validation.php:
public function valid_email($str)
{
if (function_exists('idn_to_ascii') && preg_match('#\A([^#]+)#(.+)\z#', $str, $matches))
{
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($matches[2]);
if ($domain !== FALSE)
{
$str = $matches[1].'#'.$domain;
}
}
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
}
The ideal solution would be to upgrade ICU to its latest version
As this was not possible at my shared server, I resolved that problem, extending the CI email library:
overrules valid_email() function which uses INTL_IDNA_VARIANT_UTS46, which is unfortunately not installed on my server.
PhP 7.2 works with that version, so if you have INTL_IDNA_VARIANT_2003 installed, you get the above deprecated error message.
SOLUTION: you need to go back to valid_email() function from 2.0 version email library:
class MY_Email extends CI_Email {
public function valid_email($address)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*#([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
}
}
Save this extended Class as MY_email.php in your application/libraries folder. About Extending Native Libraries, the prefix MY_ is configurable.

Wordpress PHP Fatal Error with Openshift

When I try to access the plugins or themes section of my wordpress site from the admin panel I am presented with a blank screen. When I run the logs I get the following error:
Navigating to wp-admin/plugins.php:
PHP Fatal error: Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 277
Navigating to wp-admin/themes.php:
PHP Fatal error: Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 440
Solutions online indicated that I should re-add the function, or re-install Wordpress. Without access to the core files, I downloaded a local repository of the application (but noticed it did not contain any of the plugins or themes I had uploaded via the admin interface).
I extracted a plugin and theme (placing them in the respective directories) then pushed the changes to production in the hopes that it would extract and re-install an updated version of wordpress. I then restarted the app.
The error still persists and I can not validate if the plugin or theme I uploaded were installed. Is there a way to refresh or reinstall a wordpress instance on Openshift?
I'm wondering how I can fix this issue without creating a new gear and migrating my data via the database. Note: Front end is working fine.
Version of Wordpress: 4.1.1
I ended up connecting to the app via SFTP and modified the file the following directly
/var/lib/openshift/{userID}/app-root/data/current/wp-includes/functions.php
and added the following function:
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
$json = call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
Ref: https://wordpress.org/support/topic/fatal-error-call-to-undefined-function-wp_json_encode-in

phpfastcache unlink() permission denied

I'm using phpfastcache https://github.com/khoaofgod/phpfastcache/
when I try to delete the cache I get an error
Warning: unlink(C:\...//sqlite/indexing): Permission denied in C:\...drivers\sqlite.php on line 328
I usually see that kind of error when there is a process not releasing the handle of those files.
Step to reproduce
// Require phpfastcache
require_once 'phpfastcache_v2.1_release\phpfastcache\phpfastcache.php';
// Simple singleton
class MyCache extends phpFastCache
{
private static $istance;
Private $obCache;
function __construct()
{
$option = array('securityKey' => 'aCache', 'path' => dirname(__FILE__));
$this->obCache = parent::__construct('sqlite', $option);
}
public static function getIstance()
{
if( is_null(self::$istance) )
{
self::$istance = new self();
}
return self::$istance;
}
}
// check if cached
if( $CacheData = MyCache::getIstance()->get('aKeyword') )
{
die('Cached');
}
// store in cache
MyCache::getIstance()->set('aKeyword','aValue', 60*60*24);
// clean cache (throw error)
MyCache::getIstance()->clean();
die('No cached');
this is the method of "phpfastcache" that generates the error
function driver_clean($option = array()) {
// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!="..") {
unlink($this->path."/".$file);
}
}
}
does anyone know how to fix this?
I'm temporarily using #unlink()
I tried but nothing has changed
chmod($this->path."/".$file, 0777);
unlink($this->path."/".$file);
UPDATE
I'm under windows...
UPDATE 2
I installed XAMPP using the admin account, after installation run with admin privileges...
UPDATE 3
Solution:
function driver_clean($option = array()) {
// close connection
$this->instant = array();
$this->indexing = NULL;
// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!="..") {
unlink($this->path."/".$file);
}
}
}
The solution depends on the environment that serves the script.
If it's CLI, the ability to creating, deleting or modifing files are controlled by the executing user.
If it's a PHP Stack ( WAMP, XAMPP, ZendServer or own Webserver+PHP+MySQL-Stack ) the executing layer ( apache, nginx ) must use an user which has rights to do what you want to do.
In both cases it depends on what you've configured or what had been inherited to your script, directory or drive.
Permission Knowledge could be found here: http://technet.microsoft.com/en-us/library/cc770962.aspx
(Doesn't work under Windows) Try to change permissions before:
chmod($yourfile, '0777');
unlink($yourfile);

How to implement SSL in Zend MVC

I have implemented secure pages before by using a specific secure folder (eg https folder vs http folder on the server). I have started using Zend Framework and would like parts of the application (eg login) to use https. I have searched on google and even here but could not find anything that explains how to handle this. Can I have https for specific controllers/actions? Thanks.
The cleanest way is to have an .ini file for the SSL config where you can enable SSL support for model/controller/action levels, like so:
Let's say you have a module/controller/action like this:
SSLModule->IndexController->testAction
## ini file (can be config.ini also)
ssl.modules.SSLModule.require_ssl = true //-> entire module requires SSL
ssl.modules.SSLModule.Index.require_ssl = true //-> entire controller requires SSL
ssl.modules.SSLModule.Index.test.require_ssl = true //-> single action requires SSL
You parse this either through config, or separately, and in your Bootstrap file you can include a controllerplugin, like mine here.
There are many other ways to do this, but I think you get the idea!
class Application_Controllerplugins_Ssl extends Zend_Controller_Plugin_Abstract
{
public function preDispatch ( Zend_Controller_Request_Abstract $request )
{
$shouldSecureUrl = false;
//get the config settings for SSL
$options = Application_ServiceManager::getConfig()->ssl;
//if config is empty, exit
if (!is_object($options))
return;
//simpler to use
$options = $options->toArray();
//only use it production environment
if ( APPLICATION_ENV == 'production' )
{
if (
( isset($options['modules'][$request->module]['require_ssl']) && $options['modules'][$request->module]['require_ssl'] ) ||
( isset($options['modules'][$request->module][$request->controller]['require_ssl']) && $options['modules'][$request->module][$request->controller]['require_ssl'] ) ||
( isset($options['modules'][$request->module][$request->controller][$request->action]['require_ssl']) && $options['modules'][$request->module][$request->controller][$request->action]['require_ssl'] )
)
{
$shouldSecureUrl = true;
}
if ( $shouldSecureUrl )
{
$this->_secureUrl($request);
}
}
}
protected function _secureUrl ( Zend_Controller_Request_Abstract $request )
{
$server = $request->getServer();
$hostname = $server['HTTP_HOST'];
if ( ! $request->isSecure() )
{
$url = Zend_Controller_Request_Http::SCHEME_HTTPS . "://" . $hostname .
$request->getPathInfo();
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->setGoToUrl($url);
$redirector->redirectAndExit();
}
}
}
I forgot to mention: to add it in your bootstrap:
$Zend_Controller_Front->registerPlugin( new Application_Controllerplugins_Ssl() );

PHP/Codeigniter FTP Timeout

I'm trying to access an FTP server from my PHP script using Codeigniter's FTP Library. These functions work great, but when testing the script I discovered that if I attempt to connect to a server that does not exist, the script does not terminate with an error message of any kind.
The page continues to execute, until the web server gives up, returning an empty document.
So I am wondering, is there a way to limit the amount of time that Codeigniter can try to connect to an FTP server, then display a message if that times out?
I tried using the php function set_time_limit(), but it does not behave how I expected it to.
Thanks for your help.
Codeigniter's ftp class uses the underlying ftp_connect php call that supports a 3rd optional parameter, timeout (http://ca2.php.net/manual/en/function.ftp-connect.php).
Codeigniter however does not use it, but allows for extending the default libraries it provides (providing that you're willing to do some work and check that any updates you do to the core will not break the functionality of your extended class). So to solve your problem you could create a new library in you application library folder:
<?php
class MY_FTP extends CI_FTP { //Assuming that in your config.php file, your subclass prefix is set to 'MY_' like so: $config['subclass_prefix'] = 'MY_';
var $timeout = 90;
/**
* FTP Connect
*
* #access public
* #param array the connection values
* #return bool
*/
function connect($config = array())
{
if (count($config) > 0)
{
$this->initialize($config);
}
if (FALSE === ($this->conn_id = ftp_connect($this->hostname, $this->port, $this->timeout)))
{
if ($this->debug == TRUE)
{
$this->_error('ftp_unable_to_connect');
}
return FALSE;
}
if ( ! $this->_login())
{
if ($this->debug == TRUE)
{
$this->_error('ftp_unable_to_login');
}
return FALSE;
}
// Set passive mode if needed
if ($this->passive == TRUE)
{
ftp_pasv($this->conn_id, TRUE);
}
return TRUE;
}
}
?>
and from your script, you could add to your configuration array the timeout option:
$this->load->library('ftp'); //if ftp is not autoloaded
$ftp_params = array('hostname'=>'1.2.3.4', 'port'=>21, 'timeout'=>10); //timout is 10 seconds instead of default 90
$ftp_conn = $this->ftp->connect($ftp_params);
if(FALSE === $ftp_conn) {
//Code to handle error
}
The ftp class is not designed to give error messages unless the debug parameter is set to TRUE in te config array, in which case it'll just display an error. However it can also be override, because all errors call the function _error() in the class. So you could set 'debug' => true in your $ftp_params array, and add a function in MY_ftp like so:
/**
* This function overrides
*/
function _error($line)
{
$this->error = $line;
}
And then have a function getError()
/**
* This function overrides
*/
function get_error()
{
return $this->error;
}
So if
$ftp_conn = $this->ftp->connect($ftp_params);
returns false, you can call
$error = $this->ftp->get_error();
to get your error and display it.
Now, you can always customize and have a more complex error handling mechanism by further customizing the class...
Hope it answers your question.
The answer is simple, don't attempt to connect to a server that doesn't exist.

Categories