<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Phantom instances]]></title><description><![CDATA[<p>I am using jsreport-core to convert html to pdf and send the pdf by email.</p>
<p>My structure is the following:</p>
<pre><code class="language-js">var jsreport = require ('jsreport-core') ();

var contentPDF = '&lt;html&gt; &lt;body&gt; hello world and other things ... &lt;/ body&gt; &lt;/ html&gt;';

jsreport.init (). then (function () {
    return jsreport.render ({
      template: {
        content: contentPDF,
        engine: 'none',
        recipe: 'phantom-pdf'
      }
    })
});
</code></pre>
<p>I have a service on my server that runs every so often, generates the reports that I have to generate and sends them, but I'm having problems with my server because phantom creates several instances and consumes a lot of memory and causes my server to die.</p>
<p>I'm trying to use something like this:</p>
<pre><code class="language-js">var jsreport = require ('jsreport-core') ();
jsreport.use (require ('jsreport-phantom-pdf') ({&quot;numberOfWorkers&quot;: 1, &quot;strategy&quot;: &quot;phantom-server&quot;}));
</code></pre>
<p>but it seems to have no effect; Do you have any suggestions or help that you can give me? Is that the solution or is there something that is ignoring or doing wrong?</p>
<p>I appreciate the help you can give me.</p>
]]></description><link>https://forum.jsreport.net/topic/321/phantom-instances</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 03:56:35 GMT</lastBuildDate><atom:link href="https://forum.jsreport.net/topic/321.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Nov 2017 03:30:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Phantom instances on Tue, 21 Nov 2017 07:17:38 GMT]]></title><description><![CDATA[<p>I am using jsreport-core to convert html to pdf and send the pdf by email.</p>
<p>My structure is the following:</p>
<pre><code class="language-js">var jsreport = require ('jsreport-core') ();

var contentPDF = '&lt;html&gt; &lt;body&gt; hello world and other things ... &lt;/ body&gt; &lt;/ html&gt;';

jsreport.init (). then (function () {
    return jsreport.render ({
      template: {
        content: contentPDF,
        engine: 'none',
        recipe: 'phantom-pdf'
      }
    })
});
</code></pre>
<p>I have a service on my server that runs every so often, generates the reports that I have to generate and sends them, but I'm having problems with my server because phantom creates several instances and consumes a lot of memory and causes my server to die.</p>
<p>I'm trying to use something like this:</p>
<pre><code class="language-js">var jsreport = require ('jsreport-core') ();
jsreport.use (require ('jsreport-phantom-pdf') ({&quot;numberOfWorkers&quot;: 1, &quot;strategy&quot;: &quot;phantom-server&quot;}));
</code></pre>
<p>but it seems to have no effect; Do you have any suggestions or help that you can give me? Is that the solution or is there something that is ignoring or doing wrong?</p>
<p>I appreciate the help you can give me.</p>
]]></description><link>https://forum.jsreport.net/post/1551</link><guid isPermaLink="true">https://forum.jsreport.net/post/1551</guid><dc:creator><![CDATA[Gustavo Navarro]]></dc:creator><pubDate>Tue, 21 Nov 2017 07:17:38 GMT</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Tue, 21 Nov 2017 07:25:48 GMT]]></title><description><![CDATA[<p>This initialization should result in using single phantomjs worker. Try to print logs to console.<br />
For example by setting this at the top of your file.</p>
<pre><code class="language-js">process.env.debug = 'jsreport'
</code></pre>
]]></description><link>https://forum.jsreport.net/post/1554</link><guid isPermaLink="true">https://forum.jsreport.net/post/1554</guid><dc:creator><![CDATA[jan_blaha]]></dc:creator><pubDate>Tue, 21 Nov 2017 07:25:48 GMT</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>Or write some debug information <a href="https://github.com/pofider/phantom-workers/blob/master/lib/phantomManager.js#L19" rel="nofollow">here</a> .</p>
]]></description><link>https://forum.jsreport.net/post/1555</link><guid isPermaLink="true">https://forum.jsreport.net/post/1555</guid><dc:creator><![CDATA[jan_blaha]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>I'm not good at debugging, but checking the phantomManager.js file I could verify that if the parameters are being passed and Phantom creates the instances that I configured.</p>
<p>var PhantomManager = module.exports = function (options) {<br />
this._phantomInstances = [];<br />
this.options = options || {};<br />
this.options.workerEnv = this.options.workerEnv || {};<br />
this.options.numberOfWorkers = this.options.numberOfWorkers || numCPUs;<br />
console.log('PhantomManager this.options.numberOfWorkers ', this.options.numberOfWorkers);//log*************<br />
this.options.timeout = this.options.timeout || 180000;<br />
this.options.host = this.options.host || &quot;127.0.0.1&quot;;<br />
this.options.hostEnvVarName = this.options.hostEnvVarName || &quot;PHANTOM_WORKER_HOST&quot;<br />
this.options.portEnvVarName = this.options.portEnvVarName || &quot;PHANTOM_WORKER_PORT&quot;;<br />
this._timeouts = [];<br />
this.tasksQueue = [];<br />
};</p>
<p>The problem is that you are not deleting those instances or reusing them, simply create new ones, which leaves my server without memory. I believe that with the kill method it removes the instances when the process ends:</p>
<p>process.once(&quot;exit&quot;, function () {<br />
self.kill();<br />
});</p>
<p>But he is not eliminating them. Help me please.</p>
]]></description><link>https://forum.jsreport.net/post/2024</link><guid isPermaLink="true">https://forum.jsreport.net/post/2024</guid><dc:creator><![CDATA[Gustavo Navarro]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>Do you call <code>jsreport.init</code> just once? The instances should be reused if you do.</p>
]]></description><link>https://forum.jsreport.net/post/2029</link><guid isPermaLink="true">https://forum.jsreport.net/post/2029</guid><dc:creator><![CDATA[jan_blaha]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Mon, 12 Feb 2018 19:39:52 GMT]]></title><description><![CDATA[<p>That said, that would be the problem. Then I ask for your help or advice in this regard; This is what my service does:</p>
<p>I do not want to schedule tasks in the cron of my server, so I created a service in NodeJs using cronjs library, which runs every hour and check in the database the reports that are scheduled at that time, I go through the elements of the I list one by one and for each report I execute the jsreport.init method, I create the report and send it, and every hour I do the same.</p>
<pre><code>var job = new CronJob ({
cronTime: '0 0 * * * *',
onTick: function () {
    login()
    .then (getScheduledReports)
    .then (function (data) {
        data.reduce (function (promise, schReport) {

            // This is where I run the jsreport.init method and the code is similar to this one, please ignore the indentation and other details (hehe).

            jsreport.init (). then (function () {
                return jsreport.render ({
                  // parameters
                }). then (sendMail)
            });

        }, new Q ());
    }
},
start: true,
timeZone: 'America / Bogota'
});
job.start ();
</code></pre>
]]></description><link>https://forum.jsreport.net/post/2031</link><guid isPermaLink="true">https://forum.jsreport.net/post/2031</guid><dc:creator><![CDATA[Gustavo Navarro]]></dc:creator><pubDate>Mon, 12 Feb 2018 19:39:52 GMT</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>You should initialize jsreport just once. In the outer scope somewhere. Then call just <code>jsreport.render</code>.<br />
I don't understand why you call init every time, can you elaborate on it?</p>
]]></description><link>https://forum.jsreport.net/post/2032</link><guid isPermaLink="true">https://forum.jsreport.net/post/2032</guid><dc:creator><![CDATA[jan_blaha]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>I think I had a bad interpretation. I thought that the init method should be executed every time you want to render a report.</p>
]]></description><link>https://forum.jsreport.net/post/2033</link><guid isPermaLink="true">https://forum.jsreport.net/post/2033</guid><dc:creator><![CDATA[Gustavo Navarro]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Phantom instances on Invalid Date]]></title><description><![CDATA[<p>No, just once. Otherwise it would part of the render.<br />
There is quite heavy code running inside init and that is why it is extracted.</p>
]]></description><link>https://forum.jsreport.net/post/2035</link><guid isPermaLink="true">https://forum.jsreport.net/post/2035</guid><dc:creator><![CDATA[jan_blaha]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>