So, I have looked at other answers with the same error but none of their solutions have answered my question.
I have a mysql table with ~10k names in it and I have 25 instances (listening on different ports) of a nodejs file that each send a request to grab 400 names from database through a php file. If I set the request to grab like 100 - 150 it works but if I tell it to get more than 200, I get the error 'unexpected end of input'.
This is my nodejs request:
function user_acquire()
{
var request = require('request');
var http = require('http');
var post_options = {
host: 'localhost',
path: '/name_request.php?pos1=50&pos2=150', //this is where the amount to request is set & range
method: 'POST',
headers: {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded',
}
};
// Set up the request
var post_req = http.request(post_options, function (res) {
res.on('data', function (chunk) {
usernames = JSON.parse(chunk);
});
});
post_req.end();
}
And this is the php file the nodejs communicates with:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$conn = new mysqli($servername, $username, $password, $dbname, '3306');
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$start = $_GET['pos1'];
$end = $_GET['pos2'];
$sql = mysqli_query($conn, "SELECT * FROM preliminary_tests WHERE ID BETWEEN '$start' AND '$end'");
$array = mysqli_fetch_all($sql, MYSQLI_ASSOC);
print_r(json_encode($array,JSON_UNESCAPED_UNICODE));
?>
using JSON_UNESCAPED_UNICODE
doesn't fix the problem. I know the mysql is encoded in utf-8
. Both of these functions work with smaller requests but increasing the request size breaks one and I'm not sure why