My problem is that memcache logic inside my cakePHP application is not working on my local system, ever since I set it up here, by taking code from existing setup of teammates. I have checked that Memcached service is running on my system and phpinfo() shows memcache section enabled.
But, things like these are not working -
$this->Memcache->set($key,$value);
CakePHP uses its wrapper for Memcache, v. 0.3.
If I debug like this -
echo "<pre>";
echo "checking";
error_reporting(-1);
$this->Memcache->set($key,$countryNetworkWiseReportData,3600);
echo "finished";
exit;
I get -
checkingfinished
Strict standards: Non-static method Cache::write() should not be called statically, assuming $this from incompatible context in D:\cake1.2\cake\libs\configure.php on line 690
... and similar strict standard notifications for Cache::getInstance() etc.
But note the notifications appear after "checkingfinished", so I am confused if that is actually relevant.
I tried the command -
telnet 127.0.0.1:11211
Which gives -
Connecting To 127.0.0.1:11211...Could not open connection to the host, on port 23: Connect failed
Also tried -
telnet localhost:11211 (in case firewall issues prevent connection to 127.0.0.1)
But got the same error.
I also tried this script called memcache.php. I put $arr= "127.0.0.1:11211"; in the code and I got this result on my system -
What do I interpret from this data? I am getting a Warning in the Start time section - Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the ....
So far, it appears to me that connection to the default port 11211 is due to some reason not allowed in my cakePHP project code. But again, how then memcache.php is able to connect to the memcache server and able to display those data.
Further Details
Thanks to Tudor Constantin, doing telnet 127.0.0.1 11211 does not throw any error anymore, shows an empty screen... which I guess is fine.
I checked further in code, we have model functions which have logic like this -
if(!$this->memcacheCommon())
{
$this->log('Error in memcache', LOG_DEBUG);
die('Error in memcache');
}
//like in others system, in my system too, it passes above condition
$memcachedata = $this->Memcache->get($key);
//does not return data in my system, because $this->Memcache->set($key,$data); never sets the data correctly.
if(got data from memcache)
{
//Return that data
}
else
{
//Get data from database
$this->Memcache->set($key,$data); //does not the data in my setup - set() function returns false
}
So, I went inside the set() function of class CakeMemcache(), and there is this line in the end
return #$this->_Memcache_cluster_new->set($key, $var, 0, time()+$expires);
this returns false, and I don’t know what to debug from here.
One more thing that is confusing me is memcacheCommon() inside app_model.php has these lines –
$this->Memcache = new CakeMemcache();
$this->Memcache->_connect();
And inside CakeMemcache()->_connect(), there are these lines –
$this->_Memcache_standalone =& new Memcache();
$this->_Memcache_cluster_new =& new Memcache();
I am not sure what exactly do they do.
Will appreciate any pointers... thanks
More Details
I have somehow lost the earlier memcache.php file, using which I got the above graphical memcache usage display (had posted the pic of the output I got, above). I later downloaded memcache-3.0.6 from http://pecl.php.net/package/memcache/3.0.6 and tried running the example.php and memcache.php files which are present inside the archive.
Firstly, running example.php gives me following error -
Notice: memcache_connect(): Server localhost (tcp 11211) failed with: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Warning: memcache_connect(): Can't connect to localhost:11211, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Connection to memcached failed
I checked that memcached service is running (in windows services list).
Also telnet localhost 11211 does not give any error and shows an empty command window.
Secondly, running memcache.php and entering the credentials, gives me the following, on clicking all the tabs (Refresh Data, View Host stats, variables ) -
Notice: Use of undefined constant values - assumed 'values' in path\to\file\memcache.php on line 57
Cant connect to:v:a
Line 57 was -
function get_host_port_from_server($server){
$values = explode(':', $server);
if (($values[0] == 'unix') && (!is_numeric( $values[1]))) {
return array($server, 0);
}
else {
return values; //line 57
}
}
How come that was values, I downloaded it from http://pecl.php.net/package/memcache/3.0.6. After I changed it to return $values; I got ->
Cant connect to:mymemcache-server1:11211
. I don't exactly remember how earlier I was able to get that memcache server graph (I posted the pic above).
Thirdly, on command line, after connecting via telnet, command stats gives the following -
STAT pid 1584
STAT uptime 2856
STAT time 1315981346
STAT version 1.2.1
STAT pointer_size 32
STAT curr_items 0
STAT total_items 0
STAT bytes 0
STAT curr_connections 1
STAT total_connections 3
STAT connection_structures 2
STAT cmd_get 0
STAT cmd_set 0
STAT get_hits 0
STAT get_misses 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 67108864
END
As I can see, you are on a windows machine, so the telnet command is:
telnet 127.0.0.1 11211
Notice the space instead of colon. This might help you debug the memcache connection
Yay! I found the solution!! It started working after I changed localhost to 127.0.0.1 in the /app/config/fcore.php file.
Made the following changes -
# Memcache server constants
define('MEMCACHE_SERVER', 'localhost:11211');
define('MEMCACHE_SERVER_CLUSTER', 'localhost:11211');
define('MEMCACHE_SERVER_CLUSTER_NEW', 'localhost:11211');
to
# Memcache server constants
define('MEMCACHE_SERVER', '127.0.0.1:11211');
define('MEMCACHE_SERVER_CLUSTER', '127.0.0.1:11211');
define('MEMCACHE_SERVER_CLUSTER_NEW', '127.0.0.1:11211');
Oh, I suffered so much due to this and I think I could not, in my life, fix this.
Luckily, our team setup a new repository for the project with 127.0.0.1 instead of localhost and when I took checkout memcache started working and later I realized this was the reason.
Related
Using Ajax integrated chat with PHPBB3. It is supposed to use the mysql connections that the site uses. The database tables have been created. When accessing, I continue to get the error
'>[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/di/container_builder.php on line 291: file_put_contents([ROOT]/chat/../cache/container_[ROOT]/chatslashdotdotslash.php): failed to open stream: Invalid argument Error-Report: No connection could be made because the target machine actively refused it. Error-Code: 2002'
Edit: I have not had any trouble connecting to the database with the web application itself. I've read that the hosts file may need to be edited. I made sure that the socket server option for AJAX chat is set to false. I'm not sure what this error is actually trying to say here or what the actual connection error is. Can someone point me in the right direction?
The php class container_builder is where the error falls. Here is the function being called at that point:
protected function dump_container($container_filename)
{
$dumper = new PhpDumper($this->container);
$cached_container_dump = $dumper->dump(array(
'class' => 'phpbb_cache_container',
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
));
file_put_contents($container_filename, $cached_container_dump);
I cleared out the particular cache file, which was then recreated, but the error does not go away. I would think there is no problem with connectivity to the database by the application. Cache is stored on the server not the database.
My development team is having trouble accessing a remote MongoDB database from their local development environments.
The remote Ubuntu development server is running the newest v2.4.3 of MongoDB and PHP 5.3 with the mongo-php-driver v1.3.7 built for PHP 5.3. mongodb.conf is nearly empty except for basic path setup. There are currently no shards or replica sets.
All team members are using OSX 10.8, PHP 5.3, and have the mongo-php-driver v1.3.7 built for PHP 5.3. Some team members use XAMPP, others are using the built-in OSX AMP stack. We test on all major desktop browsers.
Whenever a page needs to grab data from Mongo, we start by calling this connection function:
public static function connect($server, $db)
{
$connection = new MongoClient(
"mongodb://{$server}:27017",
array(
"connectTimeoutMS" => 20000,
"socketTimeoutMS" => 20000
)
);
return $connection->$db;
}
However, nearly 30% of page loads are experiencing the following error:
Failed to connect to: www.development-server.com:27017: send_package: error reading from socket: Timed out waiting for header data
It seems that a large portion of those errors occur when refreshing a page, rather than navigating to a new page, but that's more of a guess than a fact. I've checked everyone's php.ini file and confirmed that default_socket_timeout = 60 is set.
The development server also hosts a copy of the site, but has never thrown the error, presumably since it's only calling localhost to get there. When I installed MongoDB locally, the errors also went away.
This really appears to be a timeout issue, but I cannot find any further settings, parameters, or configurations to adjust the expiry period. Are there any?
The response from #hernan_arg got me thinking about another possibility. Instead of relying on the one-and-only connection attempt to succeed (which seems to take forever), is it acceptable to stick the connection in a loop until it succeeds?
public static function connect($server, $db)
{
$connection = null;
try {
$connection = new MongoClient("mongodb://{$server}");
} catch (MongoConnectionException $e) {
return self::connect();
exit;
}
return $connection->$db;
}
Logging indicates that when the connection does fail, it fails quickly and the loop will establish a new connection in a much more timely manner than the infinite timeout does. Supposing the database becomes unreachable I'm assuming I can rely on PHP execution timeout to eventually kill the process.
try connect without the port in connection or set
array(
"connectTimeoutMS" => -1,
"socketTimeoutMS" => -1
)
(infinite timeout)
The 1.4.1 release of the driver addresses some stability issues over unstable networks.
Assuming you are talking to a replicaset, the driver will discard of servers that are being unreasonably slow - rather then reattempt to connect to them the driver will now blacklist it for few seconds without throwing these exceptions upon connection (assuming we can connect to atleast one server)
I'm learning PHP MYSQL and trying to create a database.
I'm following this tutorial
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
So far I'm testing to see if the server has access to MySQL. When I use the following code.
?php
class RedeemAPI {
private $db;
// Constructor - open DB connection
function __construct() {
$this->db = new mysqli('localhost', 'username', 'password', 'promos');
$this->db->autocommit(FALSE);
}
// Destructor - close DB connection
function __destruct() {
$this->db->close();
}
// Main method to redeem a code
function redeem() {
// Print all codes in database
$stmt = $this->db->prepare('SELECT id, code, unlock_code, uses_remaining FROM rw_promo_code');
$stmt->execute();
$stmt->bind_result($id, $code, $unlock_code, $uses_remaining);
while ($stmt->fetch()) {
echo "$code has $uses_remaining uses remaining!";
}
$stmt->close();
}
}
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI;
$api->redeem();
?
I get the following error:
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/user/Sites/promos/index.php on line 8
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): No such file or directory in /Users/user/Sites/promos/index.php on line 8
Warning: mysqli::autocommit() [mysqli.autocommit]: Couldn't fetch mysqli in /Users/user/Sites/promos/index.php on line 9
Warning: mysqli::prepare() [mysqli.prepare]: Couldn't fetch mysqli in /Users/user/Sites/promos/index.php on line 20
Fatal error: Call to a member function execute() on a non-object in /Users/user/Sites/promos/index.php on line 21
Did I perhaps forget to enable something?
It might explain why I cannot connect via my IP address to sequel pro and only to 127.0.0.1?
Apache servers use '127.0.0.1' instead of 'localhost'
There are two settings you have to check for this to work (assuming you have MySQL server installed of course):
Check the value of mysql.default_socket in your PHP configuration.
Check the value of socket in your MySQL configuration file under the [mysqld] heading.
Those values have to be identical; if they're not, change one to match the other and restart respective service.
This seems to be a common issue, as googling for it yields quite a few results. I experienced this on my two linux boxes as well (never under Windows though) and at some point I resolved to just use 127.0.0.1 on all dev servers. Basically, localhost makes the connection to the MySQL server use a socket, but your configuration doesn't point to the socket file correctly.
Here are a couple of resources that you might find useful:
http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/ - basically what #Jack suggests, but more in depth
Can't connect to MySQL on Mac -- missing mysql.sock file - here's how to locate your socket file (for some reason, my php.ini had the path wrong, and I assume your case could be similar).
I hope this helps.
I am using predis, it's subscribed to a channel and listening. It throws the following error (below) and dies after 60 secs exactly. It's surely not my web servers error or its timeout.
There is a similar issue being discussed here. Could not get much of it.
I tried setting connection_timeout in predis conf file to 0, but doesn't helps much.
Also if i keep using (send data to it and it processes) the worker it doesn't give any error. So its likely a timeout somewhere, and that too in connection.
Here is my code snippet, which is likely producing error, because if data is given to worker it runs this code and go forward, which produces no error after that.
$pubsub = $redis->pubSub();
$pubsub->subscribe($channel1);
foreach ($pubsub as $message) { //doing stuff here and unsubscribing from channel
}
Trace
PHP Fatal error: Uncaught exception 'Predis\Network\ConnectionException' with message 'Error while reading line from the server' in Predis/Network/ConnectionBase.php:159 Stack trace:
#0 library/vendor/predis/lib/Predis/Network/StreamConnection.php(195): Predis\Network\ConnectionBase->onConnectionError('Error while rea...')
#1 library/vendor/predis/lib/Predis/PubSub/PubSubContext.php(259): Predis\Network\StreamConnection->read()
#2 library/vendor/predis/lib/Predis/PubSub/PubSubContext.php(206): Predis\PubSub\PubSubContext->getValue()
#3 pdf/file.php(16): Predis\PubSub\PubSubContext->current()
#4 {main} thrown in Predis/Network/ConnectionBase.php on line 159
Checked the redis.conf timeout too, its also disabled.
Just set the read_write_timeout connection parameter to 0 or -1 to fix this. e.g.
$redis = new Predis\Client('tcp://10.0.0.1:6379'."?read_write_timeout=0");
Setting connection parameters is documented in the README. The author of Redis noted the relevance of the read_write_timeout parameter to this error in an issue on GitHub, in which he notes that:
If you are using Predis in a daemon-like script you should set read_write_timeout to -1 if you want to completely disable the timeout (this value works with older and newer versions of Predis). Also, remember that you must disable the default timeout of Redis by setting timeout = 0 in redis.conf or Redis will drop the connection of idle clients after 300 seconds of inactivity.
I had similar problem, better solution to the situation is not setting the timeout to 0 but using a exponential backoff and set the upper and the lower limit.
Change in the config parameter connection_timeout to 0 will also solve the issue.
I got the resolution to the problem. So, there is a limit to ports that a application server can connect to a particular application on another machine. These ports were getting exhausted.
We increased the limit and the problem got resolved.
How we got to know about this problem ?
In php, we were getting "Cannot assign requested address" error while creating a socket (error code 99).
At /etc/redis/redis.conf , set
timeout = 0
I'm using Heroku and solved this problem with switching from Redis Heroku to Redis Enterprise addon and then:
use Predis\Client as PredisClient;
To solve collision with GuzzleHttp\Client. You can leave the
as PredisClient
line if you are not usng GuzzleHttp.
And then connection:
$redisClient = new PredisClient(array(
'host' => parse_url(env('REDIS_URL'), PHP_URL_HOST),
'port' => parse_url(env('REDIS_URL'), PHP_URL_PORT),
'password' => parse_url(env('REDIS_URL'), PHP_URL_PASS)
)
);
(You can find your 'REDIS_URL' automatically prefilled in Heroku config vars).
I'm completely new to the Akelos framework, but I am familiar with PHP. When I came across the framework I knew it was exactly what I was looking for but for the life of me I cannot get it to install properly.
Here are the steps that I went through and the details of my environment:
I am on a Mac Intel, using MAMP as my main environment
I have copied the Akelos files into my project folder.
When I navigate to localhost:8888 (as setup by mamp) I first get this error message:
(Warning) Cannot modify header
information - headers already sent by
(output started at
/Users/Salman/Work/_PERSONAL
PROJECTS/Web
Development/PHP_Development/SPM/public/index.php:50)
But when I refreshed the page that warning disappears and I successfully obtain the Akelos Getting Started page
I setup the database configuration, and proceed
I successfully set the language settings
First I get the following error:
(User Error) Could not create or alter
table akelos_migrations using the SQL
CREATE TABLE akelos_migrations ( id
INTEGER NOT NULL AUTO_INCREMENT, name
VARCHAR(255), version
INTEGER, updated_at
DATETIME, created_at
DATETIME,
PRIMARY KEY (id) )TYPE=InnoDB
When I refresh - everything "appears" to work fine and I am taken to to the "Welcome Aboard" page
When I try to run Script / Generate I get the following message:
Warning: mysql_connect(): [2002] No
such file or directory (trying to
connect via
unix:///var/mysql/mysql.sock) in
/Users/Salman/Work/_PERSONAL
PROJECTS/Web
Development/PHP_Development/SPM/vendor/adodb/drivers/adodb-mysql.inc.php
on line 353
Warning: mysql_connect(): No such file
or directory in
/Users/Salman/Work/_PERSONAL
PROJECTS/Web
Development/PHP_Development/SPM/vendor/adodb/drivers/adodb-mysql.inc.php
on line 353
Fatal error: Connection to the
database failed.
mysqlt://salman:******#localhost/socialPM_dev
in /Users/Salman/Work/_PERSONAL
PROJECTS/Web
Development/PHP_Development/SPM/lib/AkActiveRecord/AkDbAdapter.php
on line 66
This happens even if I try to manually create the akelos_migrations table using phpMyAdmin and SQL.
I would love to be able to use this framework - but I absolutely can't get past this!
Well the mysql socket file isnt usually in /var/mysql/mysql.sock on OS X. If you use the Mysql install from Mysql then its in /tmp/mysql.sock by default... The macports version is in /opt/local/var/run/mysql5/mysqld.sock by default. Im not sure where it is in MAMP because i dont use it, but my guess would be somewhere on the MAMP folder structure. You need to find out where it creates its socket and supply the path to it to your conifguration (i assume thats an option on the DB setup screen).