7 Replies - 632 Views - Last Post: 16 June 2015 - 11:27 AM Rate Topic: -----

#1 DocNet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 11-October 12

nncron won't send arguments to php file?

Posted 12 June 2015 - 11:39 PM

First of all i want to say that i didn't know where to post this topic and that i never before used cron.

I am using nncron because i test this website on windows and wamp.

In crontab file i set this:
* * * * * D:\wamp\www\mywebsite\php\class.xmlcontroler.php timeout=test




In php file i want to check is argv[1] not null, but it is null and argv[0] is null why? Php version is 5.4.16
if (isset($argv[1])):
    echo $argv[1];
endif;



cron.tab runs script every minute if i just run like this:
* * * * * D:\wamp\www\mywebsite\php\class.xmlcontroler.php


But when i add arguments it doesnt works, and display this error every minute:
Attached Image

Why it calls subline text application??? :helpsmilie:/>/>

Thanks.

This post has been edited by DocNet: 12 June 2015 - 11:41 PM


Is This A Good Question/Topic? 0
  • +

Replies To: nncron won't send arguments to php file?

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 13,491
  • Joined: 08-August 08

Re: nncron won't send arguments to php file?

Posted 13 June 2015 - 08:03 AM

I'm guessing that since your text file is DOS/Windows you might be having a problem with line feeds. Maybe some one here who uses Windows can verify.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2340
  • View blog
  • Posts: 9,388
  • Joined: 03-December 12

Re: nncron won't send arguments to php file?

Posted 13 June 2015 - 09:07 AM

It would generally be more like,

	* * * * * php D:\wamp\www\mywebsite\php\class.xmlcontroler.php 


If your text editor is opening, it is trying to open the file, not run it.
Was This Post Helpful? 1
  • +
  • -

#4 DocNet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 11-October 12

Re: nncron won't send arguments to php file?

Posted 13 June 2015 - 09:18 AM

Oh Yea! That is solution! Thanks :online2long:/>/>/>

One more question, why this code:
if (isset($argv[1])):
    		echo $argv[1];
  		endif;


returns null? Why argv is null if i parse some arguments to script... This code is in constructor.

:code:

This post has been edited by Dormilich: 16 June 2015 - 08:51 AM

Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1836
  • View blog
  • Posts: 5,783
  • Joined: 15-January 14

Re: nncron won't send arguments to php file?

Posted 15 June 2015 - 11:15 AM

$argv is not a super-global variable, make sure you declare it as global in your constructor.
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2340
  • View blog
  • Posts: 9,388
  • Joined: 03-December 12

Re: nncron won't send arguments to php file?

Posted 15 June 2015 - 05:27 PM

What is $argv[1] and where does it come from?

If you were using it as a get you could pass it through, but any other way, I would suggest creating a separate file that calls the other. Basically making it an automated test.

What is the purpose of the file?
Was This Post Helpful? 0
  • +
  • -

#7 DocNet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 11-October 12

Re: nncron won't send arguments to php file?

Posted 16 June 2015 - 05:49 AM

To send every minute, 5 minutes and hour data from xml to my database...

I need to run sendLeagues(), sendTeams(), sendStandings(), sendTopScorers(), sendSport() every hour,
sendFixtures(),sendOdds(),calculateOdds(),fillBaby() every 5 minutes,
and sendLiveFix() every minute.

So i need to identify what is passed and run where timeout is 3600,300,60

But no success still, i try with this simple code:
public function __construct(){
	var_dump($_SERVER['argc']);
	var_dump($_SERVER['argv']);
	$numargs = func_num_args();
    echo "Number of arguments: $numargs \n";
	if($numargs>0){
		$file = fopen("errorlog.txt","w");
		fwrite($file,"Hello World. Testing!");
		fclose($file);	
	}
}


nothing,

int 0
array (size=0)
  empty
Number of arguments: 0



cron.tab
* * * * * php ../php/class.xmlcontroler.php timeout=60

Maybe my path is not ok? Does cron support ../? Same is when i use like this \, or directly
D:\wamp\www\site\php

This post has been edited by Dormilich: 16 June 2015 - 08:51 AM

Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1836
  • View blog
  • Posts: 5,783
  • Joined: 15-January 14

Re: nncron won't send arguments to php file?

Posted 16 June 2015 - 11:27 AM

func_num_args returns the number of arguments passed to the constructor, not command line arguments.

public function __construct(){
  ini_set('log_errors', 1);
  ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'errorlog.txt');
  error_reporting(E_ALL);

  $output = $_SERVER['argc'] . ' arguments; ' . print_r($_SERVER['argv'], true);
  error_log($output);
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1