This server will host a management system to access the Internet written in PHP / mysql and Mikrotik API to lock / unlock customers.
The whole routine PHP / API was working smoothly using wampp as a development platform (windows), but to put the files in PHP hosting (my server php / mysql centos 6), the functions of adding customers and managing permissions via API not responding. I see through the activity of Winbox login / logoff in RouterOS API commands as though Comm and write do not work.
Someone tell me if you need to do some kind of specific configuration commands for the API to work properly as well as worked in wampp?
Inform the Mikrotik is with the permission of API access enabled and all scripts php / mysql are working properly.
Does PHP produce any errors? Have you set your error level to “E_ALL | E_STRICT” (in both environments)? Maybe what was just a notice in WAMPP became important on CentOS.
It’s possible that your server firewall is not configured to allow outgoing connections to the router (though PHP should’ve complained if that’s the case, hence making sure you enable error reporting). Try disabling it temporarily to verify and if that’s the case, add the “php”, “php-cgi” and/or “apache” executables to the list of applications allowed to estabilish outgoing connections.
Your suggestion about CGI reminded me that the server configuration tutorial asks us to uncomment the line (; cgi.fix_pathinfo = 1) in php.ini. I returned the file and commented on it again and the scripts work, but now the values sent on variables are not included in RouterOS.
For example:
This works:
$ API-> comm ('/queue/simple/add', array (
"name" => "boenrobot"
));
The variables name havn´t spaces… the spaces in names were created by google translator. I write my messages in notepad and copy/paste on google translator page…
I realized that even writing the values directly in the array, not all the time that the values are dropped in Routeros. if I refresh the page several times, the script includes the values at will. I do not understand why …
Looking at the log, it appears you’re having some issues with the connection between the server and the router.
The reason could still be in a misconfigured firewall, but if your router is many switches away and/or serving a good number of clients, a more likely cause is that your links are weak (a buggy switch/cable) and/or that the router is simply being overloaded.
Also, as a side note, check in the “Active Users” session that you don’t have any hanging connections (you shouldn’t have such with 5.*, but just in case…).
Internet link → RB750GL → Switcher => [server centos and my development machine]
This structure is only for developing, after everything is working perfectly, the server Centos will be connected to Mikrotik serving the entire network. ie, the only currently active connections in RB750GL are my development machine and the server Centos.
I return to say that the Centos firewall is disabled.
The only possible problem left is hanged connections. In the router, check the active users in “/user active”. You should only see one or two, and no “api” sessions. If there are more, it means some connections are left hanging for a while. If that’s the case, it might be wise to close them explicitly once you’re done by sending a “/quit” command and calling the disconnect() function.
Unfortunately, it did not work. Anyway, I need a solution only for add/remove clients in the ARP table and /queue/simple, and lock / unlock customers in the queue. Do you indicate some other feature?
You mentioned in the start that it works with Windows… does it work at the very same node? That is, if you plug the windows machine in place of the CentOS (have the Windows machine directly connected to the router board), does it work?
If it does, this might be a PHP bug related to the way it uses sockets on CentOS. Solution: Use another kind of Linux and/or report this to the PHP/CentOS devs.
If even then it doesn’t work, this might be a bug in RouterOS that occurs only on that router board. Solution: Upgrade to the latest RouterOS, and if even then it doesn’t work, contact support.
If I use my scripts in Wampp server on windows, the interaction between PHP/Mikrotik works great. My PHP version, installed on Centos is 5.3.3. The version of Routeros is 5.11 running on RouterBoard 750GL.
Is Windows using the same PHP version? Again, this is a bug in either PHP or CentOS. So, if the version on CentOS is older than the one on Windows, it might be the cause. Try with PHP 5.3.10.
Then upgrade at least to that (ideally, upgrade to PHP 5.3.10 on both machines).
Looking at the changelogs for PHP 5.3.4, there have been a few stream related bug fixes… it’s possible they also affected sockets. In particular, the part
. Fixed forward stream seeking emulation in streams that don’t support seeking
in situations where the read operation gives back less data than requested
and when there was data in the buffer before the emulation started. Also
made more consistent its behavior – should return failure every time less
data than was requested was skipped. (Gustavo)