HTTP服务器(多线程版本、epoll版本)

以下注释均为测试,可忽略

绿色为文件蓝色为目录

main.c

#include "httpd.h"
                                                                                                                                      
void* thread_run(void *arg)
{
    int sock=(int)arg;
    accept_request(sock);
    printf("one accept finshed...\n");
}
 
int main(int argc,char *argv[])
{
    if(argc!=3){
        usage(argv[0]);
        return 1;
    }   
 
    int port=atoi(argv[2]);
    char *ip=argv[1];
    int listen_sock = bind_sock(port,ip);
 
#ifdef _V1_
    struct sockaddr_in client;
    socklen_t client_len=sizeof(client);
     
    int done=0;
    while(!done){
        int sock=accept(listen_sock,(struct sockaddr*)&client,&client_len);
        if(sock<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return 1;
        }
        printf("get a new connection:%s,%d\n",inet_ntoa(client.sin_addr),ntohs(client.sin_port));
        pthread_t tid;
        if(pthread_create(&tid,NULL,thread_run,(void *)sock)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return 1;
        }
        if(pthread_detach(tid)<0){                                                                                                    
            print_log(errno,__FUNCTION__,__LINE__);
            return 1;
        }
    }
#elif _V2_
    server_handler(listen_sock);
#else
    printf("no more version...\n");
    
#endif
                                                                                                                                      
    return 0;
}

httpd.h

#include <stdio.h>
#include <stdlib.h>                                                                                                                   
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <unistd.h>
#include <sys/epoll.h>
 
#define __BLOCK__ 6
#define _SIZE_ 1024
#define _DEF_HTML_ "index.html"
#define _MAX_FD_NUM_ 64
 
typedef struct buf_ptr
{  
    int sock;
    int fd;
    int fd_size;
    int pipefd;
    char ptr[4096];
}buf_t,*buf_p;                                                                                                                        
 
void usage(const char *proc);
void print_log(int err,const char *func,int line);
int bind_sock(int _port,const char *ip);
buf_p accept_request(int sock);
int server_handler(int listen_sock);

httpd.c

#include "httpd.h"
 
void usage(const char *proc)
{                                                                                                                                     
    printf("usage:%s [ip] [port]\n",proc);
}
 
void print_log(int err,const char *func,int line)
{
    printf("%s****** %d :%s\n",func,line,strerror(err));
}
 
static int set_non_block(int fd) 
{
    int OLD_FL=fcntl(fd,F_GETFL);
    if(OLD_FL<0){
        perror("fcntl");
        return -1; 
    }   
    if(fcntl(fd,F_SETFL,OLD_FL|O_NONBLOCK)<0){
        perror("fcntl");
        return -2; 
    }   
    return 0;
}
   
int bind_sock(int _port,const char *ip)
{                                                                                                                                     
    int listen_sock=socket(AF_INET,SOCK_STREAM,0);
    if(listen_sock<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return 2;
    }
   
    int opt=1;
    setsockopt(listen_sock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
   
    struct sockaddr_in local;
    local.sin_family=AF_INET;
    local.sin_port=htons(_port);
    local.sin_addr.s_addr=inet_addr(ip);
    socklen_t len=sizeof(local);
    if(bind(listen_sock,(struct sockaddr*)&local,len)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return 2;
    }
    if(listen(listen_sock,__BLOCK__)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return 2;
    }
    return listen_sock;
}   

int server_handler(int listen_sock)
{   
    //创建epoll描述符
    int epoll_fd=epoll_create(256);
    if(epoll_fd<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return 2;
    }
    
    struct epoll_event ev;
    ev.events=EPOLLIN|EPOLLET;
    ev.data.fd=listen_sock;
    //添加监听描述符事件
    if(epoll_ctl(epoll_fd,EPOLL_CTL_ADD,listen_sock,&ev)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return 2;
    }                                                                                                                                 
    
    struct epoll_event ev_set[_MAX_FD_NUM_];
    int timeout=5000;
//    int timeout=-1;

    char buf[1024];                                                                                                                   
    int ready_num=-1;
    int i=0;
    int done=0;
    while(!done){
        //等待事件的发生
        if((ready_num=epoll_wait(epoll_fd,ev_set,_MAX_FD_NUM_,timeout))<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return 2;
        }else if(ready_num==0){
            printf("epoll timeout...\n");
        }else{
            for(i=0;i<ready_num;++i){
                //printf("EPOLLIN=%d,ready_num=%d\n",EPOLLIN,ready_num);
                if(ev_set[i].data.fd==listen_sock && (ev_set[i].events&EPOLLIN)){
                    struct sockaddr_in client;
                    socklen_t len=sizeof(client);
                    //连接请求
                    int sock=accept(listen_sock,(struct sockaddr*)&client,&len);
                    if(sock<0){
                        print_log(errno,__FUNCTION__,__LINE__);
                        return 2;
                    }
                    //设置套接字为非阻塞
                    if(set_non_block(sock)<0){
                        printf("set noblock failed...\n");
                        return 2;
                    }
    
                    ev.data.fd=sock;
                    ev.events=EPOLLIN|EPOLLET;
                    //添加套接字到epoll_fd
                    if(epoll_ctl(epoll_fd,EPOLL_CTL_ADD,sock,&ev)<0){
                        print_log(errno,__FUNCTION__,__LINE__);                                                                       
                        return 2;
                    }
                    printf("get a new connection:%s,%d\n",inet_ntoa(client.sin_addr),ntohs(client.sin_port));
                 }else if(ev_set[i].events&(EPOLLIN|EPOLLET)){
                    int sock=ev_set[i].data.fd;
                    buf_p mem=(buf_p)malloc(sizeof(buf_t));
                    memset(mem,‘\0‘,sizeof(buf_t));
                    if(!mem){
                        perror("malloc");
                        continue;
                    }
                    mem->sock=sock;
   
                    buf_p tmp_buf=accept_request(sock);
                    mem->fd=tmp_buf->fd;
                    mem->fd_size=tmp_buf->fd_size;
                    mem->pipefd=tmp_buf->pipefd;
                                                                                                                                      
                    free(tmp_buf);
   
                    int index=0;
                    int ret=0;
                    if((mem->pipefd)>0){
                        while(ret=read(mem->pipefd,(mem->ptr)+index,sizeof(mem->ptr)-1-index)){//notes! there only use read  ,not recv 
                            if(ret<0){
                                print_log(errno,__FUNCTION__,__LINE__);
                                return;                                                                                               
                            }
                            index+=ret;
                        }
                        
                        //printf("index=%d\n",index);
                        //mem->ptr[index]=‘\0‘;                                                                                       
                        //printf("mem->ptr=%s\n",mem->ptr);
                    }
                    ev.events=EPOLLOUT|EPOLLET;                                                                                       
                    ev.data.ptr=mem;
                    epoll_ctl(epoll_fd,EPOLL_CTL_MOD,mem->sock,&ev);
                    ev_set[i].data.ptr=(void *)mem;//can‘t operator to ev_set[]***************
                }else if((ev_set[i].events&(EPOLLOUT)|EPOLLET)){
                    buf_p mem=(buf_p)ev_set[i].data.ptr;
                    int sock=mem->sock;
                    int fd=mem->fd;
                    int fd_size=mem->fd_size;
                    int pipefd=mem->pipefd;
                    char *buf=mem->ptr;
                    
                    if(pipefd<0){//cgi==0
                        char *status_line="HTTP/1.1 200 OK\r\n\r\n";
                        if(send(sock,status_line,strlen(status_line),0)<0){
                            print_log(errno,__FUNCTION__,__LINE__);
                            close(fd);
                            return;
                        }
                        
                        if(sendfile(sock,fd,NULL,fd_size)<0){
                            print_log(errno,__FUNCTION__,__LINE__);                                                                   
                        }
                    }else{//cgi==1
                        send(sock,buf,strlen(buf),0);
                        
                        close(pipefd);
                    }
                    printf("send file success!\n");
                    
                    epoll_ctl(epoll_fd,EPOLL_CTL_DEL,sock,NULL);
                    close(sock);
                    close(fd);
                    free(mem);
                }
            }
        }
    }
}   

static int get_line(int sock,char *buf,int size)
{   
    assert(buf);
    int index=0;
    char ch=‘\0‘;
    while(index<size-1 && ch!=‘\n‘){
        if(recv(sock,&ch,1,0)>0){//***************************************block
            if(ch==‘\r‘){
                if(recv(sock,&ch,1,MSG_PEEK)<0){
                    print_log(errno,__FUNCTION__,__LINE__);
                    return -1;
                }else{
                    if(ch==‘\n‘){
                        recv(sock,&ch,1,0);
                    }
                }
            }
            buf[index++]=ch;                                                                                                          
        }else{
            ch=‘\n‘;
        }
    }
    buf[index]=‘\0‘;
    return index;
}
   
static void handler_clear(int sock)                                                                                                   
{
    char buf[_SIZE_];
    while(get_line(sock,buf,sizeof(buf)) && strcmp(buf,"\n")){
        //printf("%s",buf);
    }
}  
   
static void echo_html(int sock,int fd,off_t size)
{  
//  printf("path=%s\n",path);
#ifdef _V1_
    char *status_line="HTTP/1.1 200 OK\r\n\r\n";
    if(send(sock,status_line,strlen(status_line),0)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        close(fd);
        return;
    }
    
    if(sendfile(sock,fd,NULL,size)<0){
        print_log(errno,__FUNCTION__,__LINE__);
    }
    printf("send file success!\n");
    close(sock);
    close(fd);
#endif
}   
    
static int exe_cgi(int sock,const char *path,const char *query_string)
{   
    char buf[_SIZE_];
    int ret=-1;
    int content_len=-1;
    char *len=NULL;                                                                                                                   
    int firstfd[2];
    int secondfd[2];
    if(strcmp(query_string,"\0")==0){//POST
        if(setenv("METHOD","POST",1)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return;
        }
        printf("export METHOD success!\n");
        while(ret=get_line(sock,buf,sizeof(buf)) && strcmp(buf,"\n")!=0){
            //printf("buf===============%s",buf);
            if(strncasecmp(buf,"Content-Length: ",15)==0){//length is 15 include a space
                buf[ret-1]=‘\0‘;
                len=buf+15;
                content_len=atoi(len);
                if(setenv("CONTENT_LENGTH",len,1)<0){//set env_var
                    print_log(errno,__FUNCTION__,__LINE__);
                    return;
                }                                                                                                                     
                printf("export CONTENT_LENGTH success!\n");
            }
        }
        printf("POST success\n");
    }else{//GET
        if(setenv("METHOD","GET",1)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return;
        }
        printf("export METHOD success!\n");
        if(setenv("QUERY_STRING",query_string,1)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return;
        }
        printf("export QUERY_STRING success!\n");
        handler_clear(sock);
        //handler_clear(sock);
        printf("GET success\n");
    }   
        
    if(pipe(firstfd)<0){                                                                                                              
        print_log(errno,__FUNCTION__,__LINE__);
        return;
    }   
    if(pipe(secondfd)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return;
    }   
    pid_t id=fork();
    if(id<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return;
    }   
    else if(id==0){
        close(firstfd[1]);
        close(secondfd[0]);
        if(dup2(firstfd[0],0)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return;                                                                                                                   
        }
        if(dup2(secondfd[1],1)<0){
            print_log(errno,__FUNCTION__,__LINE__);
            return;
        }
        close(secondfd[1]);
        close(firstfd[0]);
        execl(path,"abcdefg",NULL);
    }else{
        close(firstfd[0]);
        close(secondfd[1]);
        char ch=‘a‘;
        if(strcmp(query_string,"")==0){//POST
            while(content_len){
                recv(sock,&ch,1,0);
                write(firstfd[1],&ch,1);
                content_len--;
            }
        }
        int ret=-1;
#ifdef _V1_
        while(ret=read(secondfd[0],&ch,1)){//notes! there only use read  ,not recv 
            if(ret<0){
                print_log(errno,__FUNCTION__,__LINE__);                                                                               
                return;
            }
        //  printf("ret=%d,ch=%c\n",ret,ch);
            send(sock,&ch,1,0);
        }
        
        close(sock);
        close(secondfd[0]);
        close(firstfd[1]);
        return 0;
#elif _V2_
        return secondfd[0];
#endif  
    }   
}       
        
buf_p accept_request(int sock)
{       
    char buf[_SIZE_];
#ifdef _DEBUG_
    int ret=-1;
    while(ret=get_line(sock,buf,sizeof(buf))){
        printf("%d:%s",ret,buf);
        if(strcmp(buf,"\n")==0){
            break;
        }
    }   
#else   
    int ret=get_line(sock,buf,sizeof(buf));
    if(ret<0){
        print_log(errno,__FUNCTION__,__LINE__);
        return;
    }   
    char *method=buf;
    char *url=buf;
    char *query_string=buf;                                                                                                           
    char *protocol=buf;
        
    char path[_SIZE_*2];
    memset(path,‘\0‘,sizeof(path));
    int cgi=0;
    //if method is not both GET or POST,exit!
    if( strncasecmp(method,"GET",3)!=0 && strncasecmp(method,"POST",4)!=0 ){
        printf("method:%s\n",method);
        printf("method error!\n");
        return;
    }   
    //method is POST,running with cgi
    if( strncasecmp(method,"POST",4)==0 ){
        method[4]=‘\0‘;
        url+=5;
        cgi=1;
    }else{
        method[3]=‘\0‘;
        url+=4;
    }   
    query_string=url;                                                                                                                 
    while(*query_string!=‘?‘ && *query_string!=‘ ‘){
        query_string++;
    }   
    if(*query_string==‘?‘){
        *query_string=‘\0‘;
        query_string++;
        protocol=query_string;
        while(*protocol!=‘ ‘){
            protocol++;
        }
        *protocol=‘\0‘;
        protocol++;
        cgi=1;
    }else{
        *query_string=‘\0‘;
        protocol=query_string+1;
    }  
    char *tmp=protocol;
    while(*tmp!=‘\r‘ && *tmp!=‘\n‘){
        tmp++;
    }                                                                                                                                 
    *tmp=‘\0‘;
     
    if(strcmp(url,"/")==0){
        strcpy(path,"htdocs/");
        strcat(path,_DEF_HTML_);
    }else{
    //  strcpy(path,url+1);
        
        strcpy(path,"htdocs");
        strcat(path,url);
    }   
        
    printf("method=%s\n",method);
    printf("path=%s\n",path);
    printf("query_string=%s\n",query_string);
    printf("protocol=%s\n",protocol);
    printf("cgi=%d\n",cgi);
    printf("path=%s\n",path);                                                                                                         
        
    int fd=open(path,O_RDONLY);
    if(fd<0){//file not exist
        print_log(errno,__FUNCTION__,__LINE__);
        return;
    }   
    
    struct stat fbuf;
    if(fstat(fd,&fbuf)<0){
        print_log(errno,__FUNCTION__,__LINE__);
        close(fd);
        return;
    }   
        
    if(S_IFDIR&(fbuf.st_mode)){//dir
        printf("file is invalid!\n");
        return;
    }else if((S_IXUSR&(fbuf.st_mode)) || (S_IXGRP&(fbuf.st_mode)) || (S_IXOTH&(fbuf.st_mode))){//2binary
        cgi=1;
    }   
    int size=fbuf.st_size;                                                                                                            
        
    int pipefd=-1;
    if(cgi==0){//GET
        handler_clear(sock);
        echo_html(sock,fd,size);
    }else{//GET or POST
        pipefd=exe_cgi(sock,path,query_string);
    }   
    buf_p tmp_buf=(buf_p)malloc(sizeof(buf_t));                                                                                       
    tmp_buf->fd=fd;
    tmp_buf->fd_size=size;
    tmp_buf->pipefd=pipefd;
    return tmp_buf;
#endif  
}

Makefile

ROOT_PATH=$(shell pwd)
LDFLAGS=-lpthread
FLAGS=#-D_DEBUG_#-g
                                                                                                                                      
CC=gcc
BIN=httpd
SRC=$(shell ls *.c)
OBJ=$(SRC:.c=.o)
 
CGI_BIN=cgi_bin
 
.PHONY:all
all:$(BIN) cgi 
$(BIN):$(OBJ)
    @echo "Linking [$^] to [[email protected]]"
    @$(CC) -o [email protected] $^  $(LDFLAGS)
    @echo "Linking done..."
%.o:%.c
    @echo "Compling [$<] to [[email protected]]"
    @$(CC) -c $< -D_V2_ $(FLAGS) 
    @echo "Compling done..."
 
.PHONY:clean
clean:
    @rm -rf *.o $(BIN) output
    @for name in `echo $(CGI_BIN)`;    do        cd $$name;\                                                                                                                   
        make clean;        cd -;    done
    
.PHONY:cgi
cgi:
    @for name in `echo $(CGI_BIN)`;    do        cd $$name;        make;        cd -;    done
.PHONY:output
output:$(BIN) cgi
    @mkdir -p output/log
    @cp -rf htdocs output/
    @mkdir -p output/htdocs/cgi_bin
    @cp -f httpd output/
    @cp -f start.sh output/
    @cp -rf conf output
    @for name in `echo $(CGI_BIN)`;    do        cd $$name;\                                                                                                                   
        make output;        cd -;    done

htdocs/index.html

<html>
    <head>
        <h1>hello chehlling</h1>
    </head>
    
    <body>
        <hr/>
        <form action="cgi_bin/math_cgi" method="POST">
            data1: <input type="text" name="data1"/><br/>
            data2: <input type="text" name="data2"/><br/>
            +: <input type="radio" name="op" value="ADD"><br/>
            -: <input type="radio" name="op" value="SUB"><br/>
            *: <input type="radio" name="op" value="MUL"><br/>
            /: <input type="radio" name="op" value="DIV"><br/>
            %: <input type="radio" name="op" value="MOD"><br/>
            <input type="submit" /><br/>
        </form>
        <hr/>
    
        <img src="20.jpg" alt="mantouheqi" dth="200" height="300"/>
        </body>
</html>

cgi_math/math_cgi.cpp

#include <iostream>
#include <string>
#include <stdio.h>
#include <errno.h>
#include <vector>
#include <stdlib.h>                                                                                                                   
#include <string.h>
#define _SIZE_ 2048
 
void get_args(std::vector<std::string> &vec,const char *method)
{
    std::string query_string; 
    std::string content_length;
    char ch=‘a‘;
    int index=0;
    int ret=-1;
    char buf[_SIZE_];
    memset(buf,‘\0‘,sizeof(buf));
    if(strcmp(method,"POST")==0){//POST
        std::string content_length=getenv("CONTENT_LENGTH");
        int len=atoi(content_length.c_str());
        memset(buf,‘\0‘,sizeof(buf));
        while(len){//&& index<sizeof(buf)-1){
            ret=read(0,&ch,1);
            buf[index++]=ch;
            len--;
        }
        if(len!=0){
            printf("error!\n");
            //print_log(errno,__FUNCTION__,__LINE__);
            return;
        }
    }else{//GET
        query_string=getenv("QUERY_STRING");
//      std::cout<<"math_cgi:query_string="<<query_string.c_str()<<std::endl;
        strcpy(buf,query_string.c_str());                                                                                             
//      std::cout<<"math_cgi:buf="<<buf<<std::endl;
        index=query_string.size();
    }
    buf[index]=‘\0‘;
//  std::cout<<buf<<std::endl;
    char *end=buf+index;
    int incount=0;
    while(end!=buf){
        if(*end == ‘=‘){
            vec.push_back(end+1);
            //std::cout<<vec[incount++]<<std::endl;
        }
        if(*end == ‘&‘){
            *end=‘\0‘;
        }
        end--;
    }
}

void echo_result(std::vector<std::string> &vec)
{   
    const char *op=vec[0].c_str();
    int data1=atoi(vec[2].c_str());
    int data2=atoi(vec[1].c_str());
    int sum=0;
    char ch;
    if( strcmp("ADD",op)==0 ){
      sum=data1+data2;
      ch=‘+‘;
    }else if( strcmp("SUB",op)==0 ){
      sum=data1-data2;
      ch=‘-‘;
    }else if( strcmp("MUL",op)==0 ){
      sum=data1*data2;
      ch=‘*‘;
    }else if( strcmp("DIV",op)==0 ){
      sum=data1/data2;                                                                                                              
      ch=‘/‘;
    }else if( strcmp("MOD",op)==0 ){
      sum=data1%data2;
      ch=‘%‘;
    }else{
      return;
    }
    
    std::cout<<"HTTP/1.1 200 OK\r\n\r\n";
    std::cout<<"<html>"<<std::endl;
    std::cout<<"<head>"<<std::endl;
    std::cout<<"  ";
    std::cout<<"<h1>math_cgi     ";
    std::cout<<ch <<"</h1>"<<std::endl;
    std::cout<<"</head>"<<std::endl;
    std::cout<<"<body>"<<std::endl;                                                                                                   
    std::cout<<data1<<ch<<data2<<"="<<sum<<std::endl;
    std::cout<<"</body>"<<std::endl;
    std::cout<<"</html>"<<std::endl;
}   
int main(int argc,char *argv[])
{   
    std::string method=getenv("METHOD");
    std::vector<std::string> vec;
    get_args(vec,method.c_str());
    
    echo_result(vec);
    
                                                                                                                                      
    
    return 0;
}

cgi_math/Makefile

math_cgi:math_cgi.cpp bigdata.cpp
    g++ -o [email protected] $^ -lstdc++
    
.PHONY:clean                                                                                                                          
clean:
    rm -rf math_cgi
    
.PHONY:output
output:math_cgi
    cp -f math_cgi ../output/htdocs/cgi_bin/

运行:

make output;cd output

启动服务器


运行结果:

 V2版本(即epoll模型),GET方法运行结果,并进行加法、乘法运算


《完》

时间: 2024-10-13 01:36:41

HTTP服务器(多线程版本、epoll版本)的相关文章

高版本-&gt;低版本迁移,低版本客户端连接高版本数据库EXP导出报错EXP-00008,ORA-01455,EXP-00000

生产环境: 源数据库:RHEL + Oracle 11.2.0.3 目标数据库:HP-UX + Oracle 10.2.0.4 需求:迁移部分表  11.2.0.3-->10.2.0.4,若迁移范围内的有些表在目标库已经存在,则替换. 本次迁移数据量<1G. 初定方案:低版本的客户端连接到高版本数据库,用低版本导出,低版本导入. 1.采用初定方案,目标数据库所在服务器连接到源数据库,exp导出过程中报错. ZJCRNOPDB 36: sqlplus -version SQL*Plus: Rel

关于消息推送的补充,主要介绍服务端的实现,包含object c 版本 c 版本 java 版本 php 版本 (转)

要实现消息推送功能,我们可以采用第三方(腾讯:信鸽:百度:云推送:极光推送:友盟):当然,因为各种原因,我们不能使用第三方的推送服务,那我们就需要自己编写服务端.在网上寻觅了很久,找到一篇很不错的讲解消息推送的文章,包含(object c 版本 c 版本 java 版本 php 版本)的后端实现,分享之. 原文地址:http://tanqisen.github.io/blog/2013/02/27/ios-push-apns/ 一步一步实现iOS应用PUSH功能 FEB 27TH, 2013 1

ANDROID PAD版本 PHONE版本 源码有什么 区别?

ANDROID PAD版本 PHONE版本 源码有什么 区别? 直接把frameworks/base/core/res/res/values/config.xml里面的<bool name="config_voice_capable">false</bool>改为false

&lt;Git命令使用&gt;当前版本,历史版本,版本切换

添加修改仓库中文件,用到的git命令是 git add <xx> git commit -m "xxx" 首先要说一下,在操作系统文件系统中更改仓库目录里的文件只是更改文件而已,而git管理系统并没有任何变化,我们使用git add和git commit命令是在改变git版本管理系统. 使用git log命令可以显示从最近到最远的提交日志,加上 --pretty=oneline参数可以精简显示内容. git内部有个指向当前版本的HEAD指针,当回退版本时,Git仅仅是把HE

Java学习笔记(3)----网络套接字服务器多线程版本

本例给出一个客户端程序和一个服务器程序.客户端向服务器发送数据.服务器接收数据,并用它来生成一个结果,然后将这个结果返回给客户端.客户端在控制台上显示结果.在本例中,客户端发送的数据是圆的半径,服务器生成的结果是圆的面积. 客户端通过输出流套接字的 DataOuputStream 发送半径,服务器通过输入流套接字的 DataInputStream 接收半径.服务器计算面积,然后,通过输出流套接字的 DataOutputStream 把它发送给客户端,客户端通过输入流套接字的 DataInputS

服务器迁移,php版本不同可能导致的问题

今天在服务器做了迁移以后,前台可以正常显示和调用,登陆后台显示500错误,一般这种情况下都要查看核心跳转文件,经查看发现login.php文件并没有调用.因为找不到login.php文件,那就证明这个文件里是有语法错误.打开服务器报错信息发现.Fatal error:Call-time pass-by-reference has been removed 经过查找资料发现,自己原来的服务器环境是5.2版本的,更换了服务器以后升级到了5.4版本,所以就出现了参数传递错误. Fatal error:

Dell 服务器CentOS 6.8版本系统安装

说明:我是从服务器的管理口进去安装操作系统的,把6.8版本的光碟事先插在了服务器的光驱上,然后进入服务器管理控制台(服务器管理IP)的虚拟控制台,然后从下次引导菜单下拉中选择"本地cd/DVD",服务器就会从光驱启动 1选择英文安装,下一步 2选择第一个选项,下一步 3输入主机名 4时区选择Asia/Shanghai 5输入root密码 6选择use all space,确保系统的数据都已经备份 7选择write changes to disk,因为数据都已经备份 8等待一段时间,正在

CentOS 6.3安装配置LNMP服务器,自定义php,mysql版本

准备篇 1.配置防火墙,开启80端口.3306端口 1 vim /etc/sysconfig/iptables 2 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙 3 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙 service iptables restart #重启防火

如何在Linux服务器中隐藏PHP版本

通常,大多数默认设置安装的web服务器存在信息泄露,这其中之一就是PHP.PHP 是如今流行的服务端html嵌入式语言(之一?).在如今这个充满挑战的时代,有许多攻击者会尝试发现你服务端的漏洞.因此,我会简单描述如何在Linux服务器中隐藏PHP信息. 默认上expose_php默认是开的.关闭“expose_php”参数可以使php隐藏它的版本信息. [[email protected] ~]# vi /etc/php.ini 在你的php.ini, 定位到含有expose_php的那行把On