I am confused about using php or python for implementing server program.
I seems that there are not only syntax differences.
For example, the php program is short-lived (only exist when request comes and die when response is generated) and it can only store things in DB rather than memory.
But for python (using TwistedWeb), the python program is long-lived. It can hold things in memory, doing something else when there are no request.
Am I wrong? I am confused and please help me to clarify it.
Both PHP and Python can be used for long running programs.  
PHP was designed as a embeddable programing language for web servers.  In the environment it is commonly set up in the web server (generally Apache with mod_php) has PHP running in it and the entire PHP environment is set up and torn down for each request.  
Python was designed as a general purpose language.  When used for developing web applications it is generally run separately from the web server process and it has requests routed to it by the web server (Apache, ngix, etc.)
There is no reason that this has to be this way - you can set up a Python program to run over CGI (where it will be re-started for each request) and you can set up PHP to run as a FastCGI program and it will be run separately from the web server and stay up between requests.
However, if you want to persist important information (for example statistics about the total number of requests received or the total amount of work performed) between requests you will be far better off persisting them to the filesystem (via files, a database, etc) or to another in-memory process like Redis or Memcached.  Even when the application process is run separate of the web server it often spawns several child processes and these processes are started and stopped after serving a certain number of requests (or after a certain amount of uptime) in order to release system resources.  Important information needs to be persisted elsewhere (and backed-up regularly).
php vs python for  server program