what my page do is:
.... So, when I run my first.php.. it loads second.php, everything's fine.. but what I want to know if it is possible to let it make by cron?
If not, what should I do? Thanks.
There are certain things you need to understand in this regard.
The first is that PHP can be run as either a
web server module or as a
standalone executable. When you run it as a web server module, you open it from the browser, all related web technologies
(html/css/js) etc get parsed and work in unison.
When you run it from command line using cron like say
then the php executable DOES NOT parse/understand the other web technologies and so your page will fail.
There are two workarounds for this:
Rewrite only those web-enabled parts so that the ajax/js stuff gets handled by PHP. Basically rule of the thumb is that if you are running a CLI php script, it should contain ONLY core PHP. This is the preferred way. You will need to move the ajax calls to inside the same file and just make it a single execution flow like any regular program.
If for some reason you cannot do the above, you can try something like this:
/path/to/browser http://mysite/mywebpage.php. Here what you are doing is, you are running a browser executable and then calling the webpage URL. This way the page is being executed within the browser's environment and it will be able to parse and understand the ajax/js calls.
Yes you can create a cron job in the below way.
1) download an array from different server (first.php)
2) php script parse values in first.php
3) Include the second file, second.php by include_once which executes mysql queries
4) If everything is correct insert them to database.
©2020 All rights reserved.