My Memcached server and Redis server are different from my web server, so that inside the PHP scripts I would have to make connections to these two external ip.
My concern is that, it would be better for my web server to keep its connections to the two memcached/redis servers. So that when new users request a php page, the web server does not need to connect to the memcached/redis again and again.
$redis = new Redis(); $redis -> close(); (or similarly with memcached and mysql)
I am unsure about what close actually means in this case. Does it mean close connection with the redis server for this particular php script execution? Given my previous concern, would calling close in fact hinder my performance?
Nothing really happens to "close" the actual connection from your server. This actually is more of a memory management issue within the application than a networking/infrastructure issue between servers. Consider the case where you have a running program that may instantiate an arbitrary number of objects. The close() method allows these objects to be destructed and garbage collected. If you were creating hundreds of instances without closing them as they're finished with, you'd end up with memory leaks in your application.
If you'll consistently just have one connection, and you're wondering whether to close and reopen this connection every time it needs to be used, rest assured, this is what connection pools are for. More info here. I know Predis uses connection pools. Not sure about whatever library Php uses to interface with Memcached.