php - Manual run works, but not cron -


There is a problem with a php script to get the title of a URL, but it works when it runs manually I run it through the cron.

function getTitle ($ url) {$ fh = fopen ($ url, "r "); $ Str = fread ($ FH, 7500); Fclose ($ fh); $ Str2 = Stroglager ($ str); $ Start = strpos ($ str2; "title"; title & gt; "+); 7; $ Len = strpos ($ str2, "& lt; / title & gt;") - $ start; Return $ url ($ start == 7); Return substrag ($ str, $ start, $ len); }

Then I run down, where I see the URLs in texts, and print the url with the title:

  $ data = mysql_query ('SELECT * message by message order by DESC limit 100;); While ($ rad = mysql_fetch_array ($ data)) {preg_match_all ($ pattern, $ rad ["text"], $ a); $ Count = count ($ a [1]); ($ Line = 0; $ line; $ count; $ row ++) {echo 'URL:' $ A [1] ["$ row"]. & Lt; BR & gt; '; Echo 'TITLE:'. GetTitle ($ a [1] ["$ row"]) '& Lt; BR & gt; & Lt; BR & gt; '; }}  

The above code resides in url.php. When I run manually through the browser, it works fine and prints the URL with the correct title. However, when I run as a scheduled cron job (once every minute), it writes URLs and URLs, then it seems that GetTitle always explains "$ start == 7" to be true.

Is it possible to do this over time? Does Fopen and Fred take longer? If so, how can I fix it?

I have seen a typical cron problem, env is Variables, but I do not know how this can affect it?

Any help or idea is welcome!

This usually happens because you have a different environment in your cron (or when you have a different Run as a user).

When you run it in the command line, then you have a different environment that you can read by running "env".

You can change the environment before running the environment in the running command. Like:

PATH = / bin: / usr / local / bin php myprogram.php

You should do something else that is capable of error reporting in your PHP scripts.

For example, Fopen can return FALSE and you have to catch such errors. "$ Start == 7" occurs when you include the empty string in your expression, so this can be the result of an uncontrolled error.

Error_Reporting (E_ALL) is running, while you can debug. >


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -