As per application requirement, I am trying to develop two PHP which can communicate with each other via Json. I tried searching online but didn\'t found solution.
Can
Remember that JSON means 'object notation', ie it's a way to describe an object in javascript. It's a great way to communicate at the network-level, but when you're in PHP you should be using the data structures that PHP is designed to use. Rather than work with JSON directly on either side, and especially as an alternative to a big JSON string, keep that data structured as an array and encode it right before sending. Your approach with curl is fine, though a bit custom - there's lots of nice routers that do a better job managing these sorts of requests (symfony is my favourite), but that's a separate issue.
e.g. instead of your big string, represent it as:
$data =
[ "user" => [
[ "firstName" => "Vignesh",
"lastName" => "Prajapati",
"age" => 23,
"email" => ["vignesh@gmail.com","vignesh@yahoo.com"],
"subject" => ["English","Gujarati", "Hindi"]
]
etc..
When it comes time to send it to the other server, json_encode
and go.