c++ windows 创建进程 和 传参

main.cpp

#include <iostream>
#include <vector>
#include <string>

std::vector account_list;
void ThreadTcp(LPVOID lpParam)
{
	cout << "TCP线程开始" << endl;

	vector *account_list = (vector *)lpParam;

	WSADATA wsaData;
	SOCKET hSocket;
	SOCKADDR_IN servAddr;

	int strLen = 0;
	int idx = 0, readLen = 0;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		std::cout << "WSAStartup() error" << std::endl;
	}

	hSocket = socket(PF_INET, SOCK_STREAM, 0);
	if (hSocket == INVALID_SOCKET)
	{
		std::cout << "hSocket() error" << std::endl;
	}

	memset(&servAddr, 0, sizeof(servAddr));
	servAddr.sin_addr.S_un.S_addr = inet_addr("139.224.118.131");
	servAddr.sin_family = AF_INET;
	servAddr.sin_port = htons(9035);
	int conn_ret = -111;
	if (conn_ret = connect(hSocket, (SOCKADDR*)& servAddr, sizeof(SOCKADDR)))
	{
		std::cout << "连接失败!" << std::endl;
		std::cin.get();
	}

	int n = 0;
	char recvBuf[2000];
	char sendBuf[2000];

	while (true)
	{
		ZeroMemory(recvBuf, 2000);
		recv(hSocket, recvBuf, sizeof(recvBuf), 0);
		if (strlen(recvBuf) == 0)
		{
			std::cout << "断开连接" << std::endl;
			break;
		}
		printf("recv:%s", recvBuf);
		
		for (int i = 0; i < 1000; i++)
		{
			sprintf_s(sendBuf, "Hello, This is client %d\r\n", i);
			//send(hSocket, sendBuf, strlen(sendBuf), 0);
		}

		if (std::count(account_list->begin(), account_list->end(), "100444024"))
		{
			cout << "已有账号" << endl;
		}
		else
		{
			cout << "添加登录账号" << endl;
			account_list->push_back("100444024");

			TThostFtdcBrokerIDType brokerID = "9999";
			TThostFtdcInvestorIDType investerID = "100444024";
			TThostFtdcPasswordType investerPassword = "123456";
			char tradeFrontAddr[] = "tcp://139.129.39.75:1234";
			addAccount(brokerID, investerID, investerPassword, tradeFrontAddr);
		}
	}

	closesocket(hSocket);
	WSACleanup();
}

int main()
{
    HANDLE Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadTcp, &account_list, 0, NULL);
}

php-fpm优化

今天上传多个策略,每个策略都是ajax去获取数据,当策略多了发现页面响应非常慢,打开其他页面也都是在转圈。
后台查看php-fpm log文件,发现一条

[14-Dec-2018 10:46:26] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

是子进程数已经达到设置的最大值。
查看php-fpm配置文件最大的进程才5,后面设置

pm.max_children = 30
pm.start_servers = 10
pm.max_spare_servers = 30

后面有时间好好研究下php-fpm

strtotime 大小月的问题


date("Y-m-d",strtotime("-1 month", strtotime('2018-03-31')));
//输出的是2018-03-03, 是因为系统获取到的是2018-02-31 再做日期规范化 就是2018-03-03了
//那怎么办呢
//从PHP5.3开始 date新增了修正短语,"first day of" 和 "last day of", 限定好不让date自动"规范化"
date("Y-m-d H:i:s", strtotime("first day of -1 month", strtotime("2018-03-31")));
date("Y-m-d H:i:s", strtotime("last day of -1 month", strtotime("2018-03-31")));

Linux svn操作


yum install subversion

cd /data/svn

svnadmin create test

cd test/conf
vim server.conf
将anon-access = read 前的注释去掉,再将read 改成none
将password-db = passwd 的注释去掉

vim passwd
在底部添加username = password
如:zhangsan = 123456.

启动
svnserve -d -r /data/svn

写一段PHP代码,确保多个进程同时写入同一个文件成功

一般的文件写入 我们都是使用的file_put_contents($filename, $data),一个函数就轻松写入文件,但是如过在高并发的情况下就可能出现死锁的问题;


$fp = fopen('lock.txt', 'w+');
if(flock($fp, LOCK_EX)){
fwrite($fp, 'content');
flock($fp, LOCK_UN);
}else{
echo "file is lock";
}
fclose($fp);