CodeIgniter Forums

Full Version: How run a script on host without internet?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello
I have script that it have to generate 10000 record and save it in database
I can open it in browser and it generate theirs and save in database
But if when codes is generating and adding to database,my internet is stoped or failed,so my script will stoped.
I need run this script in server but i cannot access to server
How do i run this script in server without affected internet on it?
My option is crobjob,is it good way?
Perhaps the issue is not with your internet connection but with the PHP or HTTP Server maximum execution time ...

Cronjob is good. But the same issue can occurs according with the hosting limits.
You could chunk the 10000 records, saving the last id, and do more than one execution.
Are you running the PHP script from an SSH terminal on the remote host?

e.g via something like:


Code:
php myscript.php
(11-25-2017, 08:04 AM)reactionstudio Wrote: [ -> ]Are you running the PHP script from an SSH terminal on the remote host?

e.g via something like:


Code:
php myscript.php

No i didn't have any access to server
I have only cronjob and panel for user for execute script
(11-24-2017, 03:05 PM)natanfelles Wrote: [ -> ]Perhaps the issue is not with your internet connection but with the PHP or HTTP Server maximum execution time ...

Cronjob is good. But the same issue can occurs according with the hosting limits.

In cronjob,script is executing in server? or execute in user side?
If you execute via cronjob, it runs on the server, not on your local machine unless you setup another cronjob locally.
(11-27-2017, 04:36 AM)reactionstudio Wrote: [ -> ]If you execute via cronjob, it runs on the server, not on your local machine unless you setup another cronjob locally.

So if i run script file with cronjob,actually it run local in server,is it?
And the server is stronger than my system,is it?
The script will run on whatever machine you setup the cronjob on. If you setup the cron to run daily on your remote server it will run regardless of if your local internet connection is down or not. If you setup the cron to run on your local machine, it will run locally.

If you have a script you run locally that must speak to / send data to a remote server and you want it to run automatically your local machine must be able to speak to the remote server over the internet.
Quote:So if i run script file with cronjob,actually it run local in server,is it?
Yes, a cron job runs on your web server. (Or as reactionstudio said above, on whatever machine you are running the scripts on)

Quote:And the server is stronger than my system,is it?
Well, what do you mean by 'stronger'?
A web server is a computer. Your local system is a computer. You are asking if unknown computer A is 'stronger' than unknown computer B. That is clearly impossible to answer.

As natanfelles said above, your webserver will normally be configured to run any request for a limited amount of time, say 30 seconds. If your script takes longer than that set time, then it will time out and stop running.

Again, as natanfelles said next, in this situation you would make your job into small manageable chunks that do not time out, and run them say every 5 minutes until the job is done.

Hope that helps,

Paul.

PS Sometimes for small tasks that only need to be run once in a while, I would write a small script to do it that I fire manually via a url, rather than a cron job. (Obviously with authorisation and authentication that it is me, and disabling the script when not needed.) It is often, at least for me, quicker to do this than working with cron.
Pages: 1 2