mjkemp21 Posted April 20, 2011 Share Posted April 20, 2011 Some background we are creating a system that collects rain data from multiple sensors and then every 15 mins sends a packet to the main server. I have been ingesting this data fine and storing the info into my database and storing a local .txt file of the packet. To forward this packet to our back up server I have been using: shell_exec("nc backup_server_address < ".$my_p); Where $my_p is the location of the .txt file. However, I have been requested to not use nc as it creates its own process every time it is called and for scalability issues we would like to forward the packet using PHP and not require a new process every time we receive a packet. I tried do some redirect stuff using headers("Location: backup_server_address"). If anyone can help that would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/234285-forwarding-http-post/ Share on other sites More sharing options...
requinix Posted April 20, 2011 Share Posted April 20, 2011 The answer here is probably sockets: fsockopen+fwrite+fclose. Quote Link to comment https://forums.phpfreaks.com/topic/234285-forwarding-http-post/#findComment-1204151 Share on other sites More sharing options...
btherl Posted April 21, 2011 Share Posted April 21, 2011 Another option would be to do a curl request from php, posting the data to the backup server. Then you avoid a new process, but you still make a new tcp connection each time. If you have a huge amount of traffic you might consider keeping a single tcp connection open constantly, or sending the data over udp (over a reliable local network). It all depends on how much you need to scale really. Each successive optimization is more complex. Quote Link to comment https://forums.phpfreaks.com/topic/234285-forwarding-http-post/#findComment-1204353 Share on other sites More sharing options...
requinix Posted April 21, 2011 Share Posted April 21, 2011 Another option would be to do a curl request from php, That was my first thought, but I think he literally means packets. Not a full HTTP exchange. Quote Link to comment https://forums.phpfreaks.com/topic/234285-forwarding-http-post/#findComment-1204358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.