NodeJS Error: Socket Hang Up (ECONNRESET)

Users have reported this ECONNRESET error with request.get(): Error: { Error: socket hang up at TLSSocket.onHangUp (_tls_wrap.js:1137:19) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:111:20) at TLSSocket.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) code: ‘ECONNRESET’, path: null, host: ‘google.com’, port: 443 }Error: { Error: socket hang up at TLSSocket.onHangUp (_tls_wrap.js:1137:19) at Object.onceWrapper (events.js:313:30) […]

PHP Notice: Undefined offset: 1 (Array)

How to fix PHP Notice: Undefined offset: 1? This PHP snippet will generate a “Undefined Offset” notice: $parts = explode(".", "aaaa");   $data = $parts[1];   print_r($data);$parts = explode(".", "aaaa"); $data = $parts[1]; print_r($data); This happens because $parts[1] is undefined. To fix this “Undefined Offset” notice just check if isset($parts[1]): $parts = explode(".", "aaaa");   […]

How to Sleep/Wait/Pause on a NodeJs Function

I found this example code that shows how to sleep in NodeJs: function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }   async function demo() { console.log(‘Taking a break…’); await sleep(2000); console.log(‘Two seconds later, showing sleep in a loop…’);   // Sleep in loop for (let i = 0; i < 5; i++) { […]

How to Install a Module/Package/Library in NodeJs

Do you need to install a NodeJs module/package/library? First create the project directory: mkdir TestProject cd TestProjectmkdir TestProject cd TestProject Make the directory the root of your project: npm init –yesnpm init –yes Install the required NodeJs modules/packages (i.e “request”): npm install request –savenpm install request –save * With -save parameter, the installed modules will […]

NodeJs Request.Get Example with Error Handling

Here is an example of using NodeJs “request” library with error handling: var dateformat = require(‘dateformat’); var request = require(‘request’);   request.get(‘https://www.google.com/’,function(err, res, body) { if(err) console.error(‘[Request.Get] %s Error:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), err.message); console.log(‘[Request.Get] %s StatusCode:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), res.statusCode); });var dateformat = require(‘dateformat’); var request = require(‘request’); request.get(‘https://www.google.com/’,function(err, res, body) { if(err) […]

NodeJs HTTPS.Get Example with Error Handling

Here is an example of using NodeJs “https” library with error handling: var dateformat = require(‘dateformat’); var https = require(‘https’);   try { var httpsget = https.get(‘https://www.google.com/’, function(res) { console.log(‘[HTTPS.Get] %s StatusCode:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), res.statusCode); }).on("error", function(error) { console.log(‘[HTTPS.Get] %s Error:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), error.message); }); } catch(e) { console.log(‘[HTTPS.Get] %s Error:’, […]

How to Find PHP.ini Location

Need to know where is located your PHP.ini file? Locate PHP.ini with Find The best way (in my opinion) is to use “find” to locate the php.ini: find / -name php.inifind / -name php.ini You should get something like this: /etc/php/7.3/fpm/php.ini /etc/php/7.3/cli/php.ini/etc/php/7.3/fpm/php.ini /etc/php/7.3/cli/php.ini So this way you will locate PHP.ini for both PHP7 FPM and […]

How to Enable Display of Errors in PHP

First edit your PHP.ini file to make sure display_errors is enabled: display_errors = ondisplay_errors = on Then if you changed this value, you’ll need to restart PHP7-FPM process: /etc/init.d/php7.3-fpm restart/etc/init.d/php7.3-fpm restart Additionally you may prepend these lines on your PHP script: error_reporting(E_ALL); ini_set(‘display_errors’, 1); ini_set(‘display_startup_errors’, 1);error_reporting(E_ALL); ini_set(‘display_errors’, 1); ini_set(‘display_startup_errors’, 1);

Go One Directory Level Up/Back with Dirname() in PHP

For PHP < 5.3 use this: echo realpath(dirname(__FILE__) . '/..');echo realpath(dirname(__FILE__) . '/..'); For PHP 5.3 to 5.6 use this: echo realpath(__DIR__ . '/..');echo realpath(__DIR__ . '/..'); For PHP >= 7.0 use this: echo dirname(__DIR__, 1);echo dirname(__DIR__, 1); References: https://www.php.net/manual/en/function.dirname.php